Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: prevent action bash escapes #294

Merged
merged 1 commit into from
Apr 18, 2024
Merged

Conversation

rbtr
Copy link
Collaborator

@rbtr rbtr commented Apr 18, 2024

Description

@robertprast in #285 and @random-dudde over at https://github.com/random-dudde/retina/pull/1 are poking at the commit-message Action trying to pull off a bash escape exploit.

The bash escape actually exists, due to the direct usage of the PR title:

commit_msg_header="${{ github.event.pull_request.title }}"

However, this is not readily exploitable because we require approval to run workflows on all external contributions. A maintainer would need to approve the workflow, which makes it unlikely that any useful bash could be sneakily stuffed in to the title and executed.

Even getting workflow approval with a benign title and then updating it later is correctly handled by GH and requires a new maintainer approval:
image
preventing a TOCTOU malicious title swap.

With that all said...unlikely does not mean impossible, and even though it is not a zero-click attack, xz showed us that social engineering can be extremely effective.

This change removes the bash escape by staging the user-input in an intermediate environment variable at the Job level.

Related Issue

If this pull request is related to any issue, please mention it here. Additionally, make sure that the issue is assigned to you before submitting this pull request.

Checklist

  • I have read the contributing documentation.
  • I signed and signed-off the commits (git commit -S -s ...). See this documentation on signing commits.
  • I have correctly attributed the author(s) of the code.
  • I have tested the changes locally.
  • I have followed the project's style guidelines.
  • I have updated the documentation, if necessary.
  • I have added tests, if applicable.

Screenshots (if applicable) or Testing Completed

Please add any relevant screenshots or GIFs to showcase the changes made.

Additional Notes

Add any additional notes or context about the pull request here.


Please refer to the CONTRIBUTING.md file for more information on how to contribute to this project.

@rbtr rbtr requested a review from a team as a code owner April 18, 2024 19:01
@rbtr rbtr self-assigned this Apr 18, 2024
@rbtr rbtr added type/fix Fixes something area/infra Test, Release, or CI Infrastructure priority/1 P1 labels Apr 18, 2024
Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️

@robertprast
Copy link

Hey all, y'all hopped on this one quite quickly and nailed the impact assessment. Historically Ive reported similar findings on other Microsoft repos to the MSRC and was going about to fill a new report for this repo after looking more into any impact escalations (though no other vectors are jumping out to me). Overall solid stuff! Happy to provide any info on my end too

@rbtr rbtr added this pull request to the merge queue Apr 18, 2024
@rbtr
Copy link
Collaborator Author

rbtr commented Apr 18, 2024

Thanks @robertprast, if you find anything else do let us know 🙂
MSRC reports are good and they will pass findings on to us pretty quickly. You can also report directly to immediately get our attention.

@random-dudde
Copy link

Thanks @robertprast, if you find anything else do let us know 🙂 MSRC reports are good and they will pass findings on to us pretty quickly. You can also report directly to immediately get our attention.

I am running poutine on public repos, and will let you know if there will be anything else.

Merged via the queue into microsoft:main with commit 63fa8d6 Apr 18, 2024
21 checks passed
@rbtr rbtr deleted the fix/prevent-escapes branch April 18, 2024 21:14
nddq pushed a commit that referenced this pull request May 6, 2024
# Description

@robertprast in #285 and @random-dudde over at
https://github.com/random-dudde/retina/pull/1 are poking at the
[commit-message](https://github.com/microsoft/retina/blob/30a128b985bc99fc8686ef21afa1cc7358dc7dfd/.github/workflows/commit-message.yaml)
Action trying to pull off a bash escape exploit.

The bash escape actually exists, due to the direct usage of the PR
title:
```bash
commit_msg_header="${{ github.event.pull_request.title }}"
```

**However, this is not readily exploitable** because we require approval
to run workflows on _all_ external contributions. A maintainer would
need to approve the workflow, which makes it unlikely that any useful
bash could be sneakily stuffed in to the title and executed.

Even getting workflow approval with a benign title and then updating it
later is correctly handled by GH and requires a new maintainer approval:

![image](https://github.com/microsoft/retina/assets/2940321/0fcee51d-1f72-48c3-a961-41ef31124b78)
preventing a TOCTOU malicious title swap.

With that all said...unlikely does not mean impossible, and even though
it is not a zero-click attack, xz showed us that social engineering can
be extremely effective.

This change removes the bash escape by staging the user-input in an
[intermediate environment
variable](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable)
at the Job level.

## Related Issue

If this pull request is related to any issue, please mention it here.
Additionally, make sure that the issue is assigned to you before
submitting this pull request.

## Checklist

- [x] I have read the [contributing
documentation](https://retina.sh/docs/contributing).
- [x] I signed and signed-off the commits (`git commit -S -s ...`). See
[this
documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)
on signing commits.
- [x] I have correctly attributed the author(s) of the code.
- [x] I have tested the changes locally.
- [x] I have followed the project's style guidelines.
- [x] I have updated the documentation, if necessary.
- [x] I have added tests, if applicable.

## Screenshots (if applicable) or Testing Completed

Please add any relevant screenshots or GIFs to showcase the changes
made.

## Additional Notes

Add any additional notes or context about the pull request here.

---

Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more
information on how to contribute to this project.

Signed-off-by: Evan Baker <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/infra Test, Release, or CI Infrastructure priority/1 P1 type/fix Fixes something
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants