How to fix the whole catagory of shell injection
How to fix the whole catagory of shell injection
Posted Dec 6, 2024 19:51 UTC (Fri) by excors (subscriber, #95769)In reply to: How to fix the whole catagory of shell injection by raven667
Parent article: Abusing Git branch names to compromise a PyPI package
GitHub Actions workflows are defined in YAML files, where you can use syntax like ${{github.ref}} in values. Those will be expanded by the action runner when it executes the workflow. (https://docs.github.com/en/actions/writing-workflows/choo...)
One of the values in the YAML file is a shell script to execute. If you use ${{github.ref}} in there, the attacker-provided branch name will be inserted before the script is passed to the shell. The attacker doesn't even need to use $(...) in the branch name, they can simply use "; to exit from the current shell command and start a new one, and the shell sees a totally normal sequence of basic commands. (See PoC in https://github.com/advisories/GHSA-7x29-qqmq-v6qc , which is a different but similar vulnerability in exactly the same project a few months ago.)
I think the specific vulnerability here is fixed in https://github.com/ultralytics/actions/commit/89c1f380073... by moving all the ${{...}} out of the shell script block and into the 'env' block where they can't do any harm (although actually the branch name was removed entirely; presumably they didn't need it at all).
GitHub warns about this problem at https://docs.github.com/en/actions/security-for-github-ac...
Posted Dec 6, 2024 20:37 UTC (Fri)
by wahern (subscriber, #37304)
[Link] (2 responses)
Posted Dec 6, 2024 21:14 UTC (Fri)
by jwarnica (subscriber, #27492)
[Link]
Posted Dec 7, 2024 11:02 UTC (Sat)
by epa (subscriber, #39769)
[Link]
But even without any attacker, constraining inputs is still good practice, I feel. It saves you time debugging later when a stray space character got into a value and (even though you were not mixing data and code) no longer compared equal to the value without a leading space. Something like a git branch name (or a username) is not the place to allow the full flowering of human creativity with special characters. There are plenty of commit message and comment fields for that.
Posted Dec 7, 2024 5:59 UTC (Sat)
by raven667 (subscriber, #5198)
[Link] (2 responses)
What if multiple commands on a single line using `;` was also a flagged feature and not enabled by default or able to be disabled? I'm not smart enough to figure out a whole system on my own but I keep thinking we should find something as effective as SQL bind variables are in stopping unexpected command interpretation that can be applied to shell scripting, maybe the wholesale separation of the shell implementation used for interactive CLIs and for scripting and automation, to make the little bits of automation that are sprinkled _everywhere_ safer.
Posted Dec 7, 2024 10:02 UTC (Sat)
by NYKevin (subscriber, #129325)
[Link] (1 responses)
* Interactive use by a human.
Everything else is an antipattern, where the shell has been co-opted to replace a missing feature in another program (often using the shell's -c flag).
Posted Dec 7, 2024 20:15 UTC (Sat)
by raven667 (subscriber, #5198)
[Link]
I'm just frustrated at seeing this same kind of problem again
Posted Dec 7, 2024 10:57 UTC (Sat)
by fishface60 (subscriber, #88700)
[Link]
I see this bug everywhere, these yaml templating engines should require a schema define how to escape interpolated values (e.g. like ninja shell escapes everything in a command context) or that part of your data format doesn't support interpolation.
How to fix the whole catagory of shell injection
How to fix the whole catagory of shell injection
How to fix the whole catagory of shell injection
How to fix the whole catagory of shell injection
How to fix the whole catagory of shell injection
* Scripting of things that would otherwise be done interactively by a human (as a timesaving measure for human sysadmins, not as something you programmatically invoke in production).
How to fix the whole catagory of shell injection
How to fix the whole catagory of shell injection
