Repository navigation
Description
Three repo-controlled fields flow into the generated Node build script without validation or escaping: package.json's engines.npm / engines.yarn and lerna.json's npmClient. Version-selection fields should stay version fields; today their content is interpolated verbatim into executable shell.
Data flow (current main)
engines.npm—src/BuildScriptGenerator/Node/NodePlatform.cs:282:var npmVersionSpec = packageJson?.engines?.npm?.Value as string;engines.yarn—NodePlatform.cs:208:string yarnVersionSpec = packageJson?.engines?.yarn;- both passed to the template model at
NodePlatform.cs:419-420 lerna.jsonnpmClient—src/Detector/Node/NodeDetector.cs:326-329(read raw), consumed atNodePlatform.cs:238-241as the command word of"{0} run build"(NodeConstants.PkgMgrRunBuildCommandTemplate)
Rendered positions in src/BuildScriptGenerator/Node/NodeBashBuildSnippet.sh.tpl:
echo "Found yarn version spec to follow: '{{ YarnVersionSpec }}'" # L24 — double-quoted
yarn set version '{{ YarnVersionSpec }}' # L26 — single-quoted
echo "Found npm version spec to follow in package.json: '{{ NpmVersionSpec }}'" # L30 — double-quoted
npm install -g npm@'{{ NpmVersionSpec }}' # L32 — single-quotedDemonstrated shapes
Local container, own throwaway repos, running the shipped script generator — no platform deployment involved:
-
Single-quote breakout.
engines.npmset to10.0.0' ; touch /tmp/oryx_marker_breakout ; echo 'rendersnpm install -g npm@'10.0.0' ; touch /tmp/oryx_marker_breakout ; echo ''The
touchruns as its own command; the marker file exists after the generated script executes. -
Command substitution without any quote character.
engines.yarnset to1.22.0$(touch /tmp/oryx_marker_subst)is JSON-safe (no escaping needed in package.json) and fires inside the double-quotedechoon L24; the marker exists after the run. -
Control. A clean
10.0.0rendersnpm install -g npm@'10.0.0'only.
Framing (impact, honestly)
To be explicit: in the deployment lanes Oryx ships in today, the repository author already has documented arbitrary code execution in the same build container — npm install lifecycle scripts run repo-authored code, and PRE/POST_BUILD_COMMAND app settings, repo-side .deployment COMMAND, and appsvc.yaml pre/post-build accept repo-specified scripts. These interpolations grant no capability the repo author lacks today, so this is a hardening/robustness report, not a boundary-crossing one. The reasons it is still worth fixing:
- a malformed spec produces a broken or surprising generated script instead of a clean validation error at detection time;
- the fields' documented semantics (version / client selection) is silently widened to arbitrary command text, which will bite any consumer that assumes version-shaped input;
- any future build lane where repo code does not execute by design (a static-output lane, for example) would inherit the injection without inheriting the mitigating context.
Suggested fix
Validate version specs at detection time against a strict charset (semver ranges plus whitespace) and reject or ignore anything else; alternatively shell-quote every interpolated value. npmClient should be checked against the known client names (npm/yarn/pnpm) rather than interpolated as a command word. It is worth auditing every {{ ... }} placeholder that lands in an executable position in the bash templates with the same rule — the four positions above and the npmClient command word are the demonstrated ones, not necessarily the only ones.
Activity