Skip to content

Commit 7d20617

Browse files
LukeTowersclaude
andcommitted
Harden phpcs utilities against shell and option injection
Escape each changed path with escapeshellarg() and prefix it with ./ so a crafted filename can neither inject shell metacharacters nor be parsed by PHPCS as an option (e.g. --bootstrap=...). Also fixes two pre-existing style nits in phpcs-push. Matches the canonical fix in core Winter. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 7b6be3c commit 7d20617

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

.github/workflows/utilities/phpcs-pr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ if (!count($files)) {
2323
exit(0);
2424
}
2525

26-
// Escape each path so filenames are passed to the shell safely.
27-
$files = array_map('escapeshellarg', $files);
26+
// Prefix each path with ./ so a filename beginning with '-' cannot be parsed
27+
// as a PHPCS option, then escape it for safe shell usage.
28+
$files = array_map(function ($file) {
29+
return escapeshellarg('./' . $file);
30+
}, $files);
2831

2932
// Run all changed files through the PHPCS code sniffer and generate a CSV report
3033
$csv = shell_exec('phpcs --colors -nq --report="csv" --extensions="php" ' . implode(' ', $files));

.github/workflows/utilities/phpcs-push

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ if (!count($files)) {
2323
exit(0);
2424
}
2525

26-
// Escape each path so filenames are passed to the shell safely.
27-
$files = array_map('escapeshellarg', $files);
26+
// Prefix each path with ./ so a filename beginning with '-' cannot be parsed
27+
// as a PHPCS option, then escape it for safe shell usage.
28+
$files = array_map(function ($file) {
29+
return escapeshellarg('./' . $file);
30+
}, $files);
2831

2932
// Run all changed files through the PHPCS code sniffer and generate a CSV report
3033
$csv = shell_exec('phpcs --colors -nq --report="csv" --extensions="php" ' . implode(' ', $files));
@@ -66,7 +69,7 @@ fwrite(STDERR, "\e[0;31mFound "
6669
? '1 issue'
6770
: count($lines) . ' issues')
6871
. " with code quality.\e[0m");
69-
fwrite(STDERR, "\n");
72+
fwrite(STDERR, "\n");
7073

7174
foreach ($files as $file => $errors) {
7275
fwrite(STDERR, "\n");
@@ -81,4 +84,3 @@ foreach ($files as $file => $errors) {
8184
}
8285
}
8386
exit(1);
84-

0 commit comments

Comments
 (0)