fix(ci): reject newline injection in SOURCE_REF before GITHUB_ENV write - #141
Merged
theredspoon merged 1 commit intoAug 10, 2026
Merged
Conversation
SOURCE_REF sanitization only rejected values containing "/" or an empty string. A value with an embedded newline followed by a KEY=VALUE-shaped line could inject or override other env vars (e.g. TARGET_BRANCH) for later steps that read GITHUB_ENV, since it is a line-based format. Replace the ad-hoc case-statement check with a strict allowlist regex for valid single-segment ref characters, which also covers newlines and carriage returns.
Owner
Author
Independent review (Codex CLI,
|
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.
Summary
SOURCE_REF(from thesource_refworkflow-dispatch input, orgithub.ref_name) is sanitized in the "Capture mirrored source revision" step before being interpolated into a line written to$GITHUB_ENV.case "${SOURCE_REF}" in */*|"") ...) rejected values containing/or an empty string, but did not reject embedded newline (\n) or carriage-return (\r) characters.$GITHUB_ENVis a line-basedKEY=VALUEformat, aSOURCE_REFcontaining a newline followed by anotherKEY=VALUE-shaped line could inject/override other environment variables (e.g.TARGET_BRANCH) consumed by later steps in the same job — e.g. redirecting the mirror push/PR target branch in the deployment repo.SOURCE_REFis meant to be a single branch-name-shaped identifier.Fix
Replaced the ad-hoc
casecheck with a strict allowlist regex for valid single-segment ref characters (^[A-Za-z0-9._-]+$). This is a superset fix: it still rejects/and empty string (matching current behavior) and additionally rejects newlines, carriage returns, spaces, and any other unexpected characters — closing off the injection primitive rather than just patching the one payload shape.Confirmed the allowlist doesn't break the only currently-valid
SOURCE_REFvalues: the input's default (reborn-matrix-pilot) and typical branch names used on this automation branch (main,upstream-main,matrix-channel-clean, etc.) all match.Test plan
This branch is intentionally minimal (see README/.gitignore: only workflows + README + gitignore are allowed), so no test file is committed. Instead, verified with an isolated shell reproduction of the exact sanitization logic before and after the fix:
reborn-matrix-pilot,main,release_1.2.3) are still accepted./) are still rejected.SOURCE_REFpayload ofreborn-matrix-pilot\nTARGET_BRANCH=attacker-controlled-branchis rejected by the new check.\r\n) is rejected.casecheck accepted that same newline payload — reproducing the vulnerability before the fix.