Skip to content

Add Fix for bot-conditions audit rule - #921

Merged
woodruffw merged 18 commits into
zizmorcore:mainfrom
mostafa:bot-conditions-fix
Jun 28, 2025
Merged

woodruffw merged 18 commits into
zizmorcore:mainfrom
mostafa:bot-conditions-fix

Conversation

@mostafa

@mostafa mostafa commented Jun 8, 2025 •

Copy link
Copy Markdown
Contributor

This PR adds Fixes to bot-conditions audit rule, as suggested by the documentation. The bot-conditions audit rule provides three fixes that work together to secure the workflow:

  1. RewriteFragmet for actor context: fine-grained rewrites of github.actor to github.event.pull_request.user.login in conditions to ensure we check the PR author rather than the last actor.
  2. Replace for trigger: Changes pull_request_target to pull_request to prevent running with elevated permissions.
  3. Remove for conditions: Optionally removes bot conditions entirely if they're not needed.

These operations are applied in sequence to transform the workflow from using spoofable bot checks to a more secure configuration.

xref #876

@mostafa
mostafa force-pushed the bot-conditions-fix branch from 2eebc62 to 1bb7633 Compare June 11, 2025 13:01
@woodruffw

Copy link
Copy Markdown
Member

Thanks @mostafa! I'll do another review tomorrow most likely.

(I'm going to look into improving the expression APIs more generally -- they should be returning spanned AST nodes so that we don't ever have to do any offset guesswork.)

@woodruffw

Copy link
Copy Markdown
Member

Hey @mostafa, sorry for the delay here! I've been working on some expression spanning APIs that will hopefully make future interactions with the expression APIs + getting the "raw" expression from a parsed AST a bit easier.

@mostafa mostafa mentioned this pull request Jun 24, 2025
11 tasks done
@mostafa
mostafa force-pushed the bot-conditions-fix branch from 37606ca to 44dcb65 Compare June 24, 2025 15:02
@mostafa

mostafa commented Jun 24, 2025

Copy link
Copy Markdown
Contributor Author

@woodruffw Thanks for the reviews! 🙏 I rebased from main and addressed your comments.

Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
mostafa and others added 9 commits June 26, 2025 23:00
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
...for now. We might want to re-add this, but the more I
think about it the more I think that we probably
always want to flag these kinds of spoofable checks.

Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
@woodruffw woodruffw added the enhancement New feature or request label Jun 28, 2025
@woodruffw woodruffw added the autofix Auto-fix functionality label Jun 28, 2025
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
@woodruffw

Copy link
Copy Markdown
Member

Thanks a ton @mostafa! I deduped the patch generation a bit, but otherwise this is good to go 🙂

@woodruffw
woodruffw merged commit 42862eb into zizmorcore:main Jun 28, 2025
@mostafa
mostafa deleted the bot-conditions-fix branch June 28, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autofix Auto-fix functionality enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants