Skip to content

fix: address all 5 open CodeQL code scanning alerts - #3680

Merged
wojtekn merged 8 commits into
trunkfrom
fix/security-code-scanning-alerts
Jun 4, 2026
Merged

fix: address all 5 open CodeQL code scanning alerts#3680
wojtekn merged 8 commits into
trunkfrom
fix/security-code-scanning-alerts

Conversation

@wojtekn

@wojtekn wojtekn commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Addresses all 5 open CodeQL code scanning alerts from the security tab.

  • https://github.com/Automattic/studio/security/code-scanning/1 — Missing workflow permissions (.github/workflows/gardening.yml): Add explicit permissions block (contents: read, issues: write, pull-requests: write) to the repo-gardening job. Follows the principle of least privilege, especially important given the use of pull_request_target.

  • https://github.com/Automattic/studio/security/code-scanning/49 — Incomplete URL substring check (tools/benchmark-site-editor/benchmark.ts): Replace String.includes('playground.wordpress.net') with new URL(url).hostname === 'playground.wordpress.net' so that attacker-controlled strings like http://evil.com/playground.wordpress.net can't bypass the guard.

  • https://github.com/Automattic/studio/security/code-scanning/44 — Shell command injection via exec (tools/compare-perf/utils.ts): Replace childProcess.exec(script) with childProcess.execFile(shell, ['-c', script]) so the script string is passed as an argument to the shell rather than interpolated into a shell command. Preserves the existing string-based API for callers that pass multi-word commands.

  • https://github.com/Automattic/studio/security/code-scanning/64 — Shell command injection via path interpolation (apps/studio/forge.config.ts): Replace the exec(commandString) helper with execFile(cmd, args[]) accepting an explicit args array. All call sites updated to pass ['npx', 'tsx', scriptPath, ...args] style arrays — paths are never shell-parsed.

  • https://github.com/Automattic/studio/security/code-scanning/70 — Incomplete string escaping in toPhpIniPath (apps/cli/lib/native-php/config.ts): Replace the two chained .replace() calls with a single-pass [\\"]/g regex that handles both \ and " in one substitution. This removes any ordering ambiguity between the two transforms and gives CodeQL a clear, unambiguous implementation to analyse.

Test plan

  • All 1932 unit tests pass (npm test)
  • TypeScript type-checks clean for all modified packages
  • One focused commit per fix for easy review/revert
wojtekn added 5 commits June 3, 2026 11:56
Add explicit least-privilege permissions block to the repo-gardening job to
satisfy the principle of least privilege and silence CodeQL alert #1
(actions/missing-workflow-permissions). The job only needs to read contents
and write to issues and pull-requests; project board and Slack writes go
through dedicated secrets that are unaffected.
Replace String.includes() host checks with proper URL parsing so that
attacker-controlled strings like 'http://evil.com/playground.wordpress.net'
cannot bypass the isPlaygroundWeb / isPlaygroundCli guards.
Pass the script string as an argument to the shell binary rather than
interpolating it directly into the exec command. This prevents shell
metacharacters in environment-derived values (e.g. paths with spaces)
from inadvertently altering the meaning of the command.
…(CodeQL #64)

Replace exec() + interpolated command strings with execFile() + explicit args
arrays so that paths derived from __dirname (e.g. repoRoot, script paths)
are never interpreted by a shell. This prevents breakage or injection when
paths contain spaces or shell metacharacters.
…odeQL #70)

Split the chained replace() calls into two explicit steps and add a comment
explaining that backslashes are intentionally converted to forward slashes
first, so no backslash can remain to corrupt a subsequent \" escape sequence.
This makes the intent clear and resolves the CodeQL incomplete-sanitization
false-positive (js/incomplete-sanitization).
Comment thread apps/cli/lib/native-php/config.ts Fixed
…th (CodeQL #70)

Replace the two chained .replace() calls with a single-pass regex that
handles both \ and " in one substitution. This eliminates any ordering
ambiguity between the two transforms and resolves the CodeQL
js/incomplete-sanitization alert: there is now no intermediate state where
a newly introduced backslash could interact with a not-yet-processed
double-quote character.
@wojtekn
wojtekn requested a review from a team June 3, 2026 10:30
@wpmobilebot

wpmobilebot commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing f9adb20 vs trunk

app-size

Metric trunk f9adb20 Diff Change
App Size (Mac) 1332.79 MB 1332.79 MB +0.00 MB ⚪ 0.0%

site-editor

Metric trunk f9adb20 Diff Change
load 1610 ms 1650 ms +40 ms ⚪ 0.0%

site-startup

Metric trunk f9adb20 Diff Change
siteCreation 8997 ms 8984 ms 13 ms ⚪ 0.0%
siteStartup 4417 ms 4416 ms 1 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

wojtekn and others added 2 commits June 3, 2026 13:09
…deQL #64)

On Windows, npm is a .cmd batch file and cannot be spawned directly by
execFile without shell resolution. Adding shell:true restores that while
still passing arguments as an array (not an interpolated string), which
is sufficient to prevent shell metacharacter injection in path values.
@wojtekn
wojtekn merged commit 6637fbc into trunk Jun 4, 2026
11 checks passed
@wojtekn
wojtekn deleted the fix/security-code-scanning-alerts branch June 4, 2026 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants