Skip to content

Commit 9dd7371

Browse files
authored
Merge pull request #159 from danog/homepage-security-example
feat(homepage): add a security analysis example to the default snippet
2 parents a4bc3f7 + 4c0684b commit 9dd7371

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎assets/css/playground.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797

9898
.pg_compact .pg_editor {
9999
flex: 0 0 auto;
100-
height: 380px; /* 15 lines × 22px + CodeMirror padding and its 15px scrollbar gap (374px), with a little slack: no scroll for the default snippet */
100+
height: 512px; /* 21 lines × 22px + CodeMirror padding and its 15px scrollbar gap (506px), with a little slack: no scroll for the default snippet */
101101
}
102102

103103
.pg_compact .pg_statusbar {

‎src/HomepageExample.php‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* The code shown in the homepage playground, and a file cache of its /check results: every homepage view
26-
* analyzes it, and its result only changes with the settings, PHP version, level, Psalm or this site's checker.
26+
* analyzes it, and its result only changes with the code, settings, PHP version, level, Psalm or this site's checker.
2727
*/
2828
final class HomepageExample
2929
{
@@ -43,10 +43,16 @@ function takesAnInt(int $i) {
4343
$condition = rand(0, 5);
4444
if ($condition) {
4545
} elseif ($condition) {}
46+
47+
$id = $_GET['id'] ?? '';
48+
if (is_string($id)) {
49+
$pdo = new PDO('sqlite:db');
50+
$pdo->exec("DELETE FROM users WHERE id=$id");
51+
}
4652
PHP;
4753

4854
/**
49-
* OnlineChecker::getResults() for CODE, cached per settings, PHP version, level, Psalm version and checker version.
55+
* OnlineChecker::getResults() for CODE, cached per code, settings, PHP version, level, Psalm version and checker version.
5056
*/
5157
public static function results(array $settings, bool $fix_file, string $php_version, int $error_level): array
5258
{
@@ -62,6 +68,7 @@ public static function results(array $settings, bool $fix_file, string $php_vers
6268
}
6369

6470
$key = hash('sha256', json_encode([
71+
self::CODE,
6572
$settings,
6673
$fix_file,
6774
$php_version,

‎views/index.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555

5656
<p>Psalm helps people maintain a wide variety of codebases – large and small, ancient and modern. On its strictest setting it can help you <a href="articles/php-or-type-safety-pick-any-two">prevent almost all type-related runtime errors</a>, and enables you to take advantage of <a href="articles/immutability-and-beyond">safe coding patterns</a> popular in other languages.</p>
5757

58+
<p>Psalm’s <a href="/docs/security_analysis/">security analysis</a> follows user input through your code to find SQL injection, XSS and other vulnerabilities before attackers do.</p>
59+
5860
<p>Psalm <a href="https://psalm.dev/docs/manipulating_code/fixing/">also fixes bugs automatically</a>, allowing you to improve your code without breaking a sweat.</p>
5961

6062
<p>Help support Psalm’s ongoing development costs by requesting a <a href="/support">paid support contract</a> from Psalm’s maintainer.</p>

0 commit comments

Comments
 (0)