output: sanitize \r in gh-annotations to prevent GitHub Actions workflow command injection#2669
output: sanitize \r in gh-annotations to prevent GitHub Actions workflow command injection#2669djvirus9 wants to merge 4 commits intogoogle:mainfrom
Conversation
…ection GitHub Actions runners treat \r as a line boundary when parsing workflow commands. The gh-annotations formatter sanitized \n -> %0A but did not sanitize \r, allowing a package with a carriage return in its name or a crafted file path to inject arbitrary workflow commands such as ::warning::, ::add-mask::, or ::set-output:: into the runner output. Sanitize both artifactPath and renderedTable by replacing \r with %0D, mirroring the existing \n -> %0A sanitization.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
I have signed the CLA. |
G-Rath
left a comment
There was a problem hiding this comment.
I'll leave it to @another-rex to comment on if this is a vuln or not, but either way you need to include tests for this
Adds TestPrintGHAnnotationReport_CRSanitization to verify that carriage return characters in source paths are encoded as %0D rather than emitted raw, preventing GitHub Actions workflow command injection.
|
▎ Added a test in TestPrintGHAnnotationReport_CRSanitization that: Test passes locally. Also still working on the CLA check — the agreement is signed at cla.developers.google.com under danishismyname1@gmail.com (signed Mar 21). @googlebot I have signed the CLA. Please recheck. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2669 +/- ##
==========================================
- Coverage 71.67% 71.66% -0.01%
==========================================
Files 164 164
Lines 12080 12084 +4
==========================================
+ Hits 8658 8660 +2
- Misses 2794 2795 +1
- Partials 628 629 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
--format=gh-annotationssanitized\n→%0Ato prevent annotation line breaks, but did not sanitize\r. GitHub Actions runners treat\ras a line boundary when parsing workflow commands, so a carriage return embedded in a package name or file path causes the annotation to be split — with anything after\rexecuted as a new workflow command.Impact
An attacker who introduces a dependency with
\rin its package metadata (via a public registry or a crafted PR) can inject commands including::warning::,::add-mask::,::set-output::, and::stop-commands::into any CI pipeline runningosv-scanner --format=gh-annotations.Reproduction