[APS-19013] fix(security): shell injection (INJ-004) and module hijack (INJ-012) in Test Observability#1098
Open
Jimesh-browserstack wants to merge 2 commits intomasterfrom
Open
Conversation
…S-19013] INJ-012: requireModule no longer honors process.env["browserStackCwd"] for node_modules resolution. Module paths now come from process.cwd() (or the internal browserstack-cypress-cli node_modules path when invoked with internal=true), eliminating env-controlled module hijack (CWE-427).
… [APS-19013] INJ-004: drop shell:true from the spawn options in helper.js runCypressTestsLocally. spawn passes argv directly to npx so the shell is not needed. Eliminates shell-injection via metacharacters in --spec / other rawArgs reaching the local Cypress runner (CWE-78).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security Fix: APS-19013
Two High-severity vulnerabilities reported on
masterof this repo. Both remediations follow the exact guidance in the ticket (INJ-004, INJ-012). Total change: 2 insertions, 4 deletions across 2 files. Commit history kept logically split (one commit per CWE) for reviewability.Issues
bin/testObservability/helper/helper.jsspawnwithshell: truebin/testObservability/crashReporter/index.jsCVSS 3.1: 8.4 (
AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H) | OWASP A03:2021Root Cause
runCypressTestsLocallyinvokesspawn('npx', [argv...], { ..., shell: true }). Withshell: true, the entire argv is concatenated and re-parsed by the shell — any metacharacter (;,&&, backticks,$(),|) inside--specor any other passed flag executes arbitrary commands.rawArgsoriginate from CLI input (CI configs, PR diffs).crashReporter.requireModuleprependsprocess.env["browserStackCwd"]to module paths beforerequire(). An attacker who can set this env var (CI config, supply-chain compromise of any other dep that sets env vars) can plant a trojanizedmocha/cypresspackage and have it loaded.Fix Applied
helper.js(1 line):spawnalready passes argv as a separate array — no shell needed. Cypress runs the same way; only the shell-interpolation hazard goes away.crashReporter/index.js(3 lines deleted, 1 inserted):Module resolution now uses
process.cwd()(or the internal nestednode_modulespath wheninternal=true) only — no env input.Testing
master(baseline)npm testfix/APS-19013-...npm testFailure list is character-for-character identical between branches (verified by diffing the
mochafailure summaries). All pre-existing failures live inruns,fileHelpers,syncSpecsLogs,utils,init,helpers/utils— none touch the changed code paths.Direct fix verification:
grep -n "shell:" bin/testObservability/helper/helper.js→ no matches (INJ-004 ✓)grep -n "browserStackCwd" bin/testObservability/crashReporter/index.js→ no matches (INJ-012 ✓)browserStackCwd=/tmp/hijack node ...) —/tmp/hijackedis not written; module path resolution no longer honors the env var.BrowserStack Session Sanity: Not applicable to this PR. The two changed code paths are:
runCypressTestsLocally— local-only fallback runner (developer workflow when not running on BrowserStack)crashReporter.requireModule— internal helper for crash-report telemetryNeither touches BrowserStack hub interaction, capability handling, session creation, or the session lifecycle. The CLI's BrowserStack-side execution path (the
runscommand viaruns.js) is unaffected by either edit. Existing pre-merge CI on this repo will exercise the standard test surface.Jira Ticket
APS-19013
Checklist
mastershows 0 new failures