Skip to content

ci: bot workflow TOCTOU and execution hardening [PM-22117]#848

Open
m2ux wants to merge 11 commits intomainfrom
fix/PM-22117-bot-workflow-security-hardening
Open

ci: bot workflow TOCTOU and execution hardening [PM-22117]#848
m2ux wants to merge 11 commits intomainfrom
fix/PM-22117-bot-workflow-security-hardening

Conversation

@m2ux
Copy link
Contributor

@m2ux m2ux commented Mar 3, 2026

Summary

Harden four comment-triggered bot workflows against TOCTOU race conditions and expression injection vulnerabilities identified by CI/CD security audit (M-F001, M-F002, M-F003, M-F004).

🎫 PM-22117 📐 Engineering 🧪 Test Plan


Motivation

Bot workflows (rebuild-metadata-bot, rebuild-chainspec-bot, cargo-fmt-bot, fix-metadata-conflicts-bot) check out PR code by branch name instead of commit SHA, creating a TOCTOU window where unreviewed commits can be injected between the permission check and code execution. In the two earthly-based bots, this code runs with repository secret access via .envrc sourcing and Docker privileged mode. Additionally, several workflows interpolate user-supplied inputs (pr_number, strategy) directly into JavaScript execution contexts, enabling expression injection.


Changes

  • rebuild-metadata-bot.yml — SHA-based checkout, removed .envrc sourcing (set EARTHLY_CONFIG explicitly), fixed pr_number expression injection via env: block
  • rebuild-chainspec-bot.yml — SHA-based checkout, removed .envrc sourcing (set EARTHLY_CONFIG explicitly), fixed pr_number expression injection via env: block
  • cargo-fmt-bot.yml — SHA-based checkout, fixed pr_number expression injection via env: block
  • fix-metadata-conflicts-bot.yml — SHA-based checkout, fixed pr_number and strategy expression injection via env: blocks

📌 Submission Checklist

  • Changes are backward-compatible (or flagged if breaking)
  • Pull request description explains why the change is needed
  • Self-reviewed the diff
  • I have included a change file, or skipped for this reason: CI workflow-only changes, no runtime impact
  • If the changes introduce a new feature, I have bumped the node minor version
  • Update documentation (if relevant)
  • No new todos introduced

🔱 Fork Strategy

  • Node Runtime Update
  • Node Client Update
  • Other
  • N/A

🗹 TODO before merging

  • Ready for review

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

kics-logo

KICS version: v2.1.19

Category Results
CRITICAL CRITICAL 0
HIGH HIGH 0
MEDIUM MEDIUM 47
LOW LOW 3
INFO INFO 59
TRACE TRACE 0
TOTAL TOTAL 109
Metric Values
Files scanned placeholder 26
Files parsed placeholder 26
Files failed to scan placeholder 0
Total executed queries placeholder 73
Queries failed to execute placeholder 0
Execution time placeholder 11

@m2ux m2ux force-pushed the fix/PM-22117-bot-workflow-security-hardening branch from 6646de2 to c6e0b2f Compare March 3, 2026 10:35
m2ux added 5 commits March 3, 2026 10:40
…-22117]

- Checkout by commit SHA instead of branch name to close TOCTOU window
- Remove .envrc sourcing; set EARTHLY_CONFIG explicitly via env: block
- Move pr_number from direct interpolation to env: block with process.env

Made-with: Cursor
…M-22117]

- Checkout by commit SHA instead of branch name to close TOCTOU window
- Remove .envrc sourcing; set EARTHLY_CONFIG explicitly via env: block
- Move pr_number from direct interpolation to env: block with process.env

Made-with: Cursor
- Checkout by commit SHA instead of branch name to close TOCTOU window
- Move pr_number from direct interpolation to env: block with process.env

Made-with: Cursor
…on [PM-22117]

- Checkout by commit SHA instead of branch name to close TOCTOU window
- Move pr_number from direct interpolation to env: block with process.env
- Move strategy from direct interpolation to env: block with process.env

Made-with: Cursor
…into fix/PM-22117-bot-workflow-security-hardening
@m2ux m2ux marked this pull request as ready for review March 3, 2026 12:03
@m2ux m2ux requested a review from a team as a code owner March 3, 2026 12:03
@m2ux m2ux self-assigned this Mar 3, 2026
m2ux added 2 commits March 4, 2026 11:44
…flow-security-hardening

Made-with: Cursor

# Conflicts:
#	.github/workflows/rebuild-metadata-bot.yml
@m2ux
Copy link
Contributor Author

m2ux commented Mar 4, 2026

/bot rebuild-metadata

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

✅ Metadata rebuild complete. No changes detected.

@m2ux
Copy link
Contributor Author

m2ux commented Mar 4, 2026

/bot rebuild-chainspec qanet

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

❌ Chainspec rebuild failed. Check the workflow logs for details.

@m2ux
Copy link
Contributor Author

m2ux commented Mar 4, 2026

/bot rebuild-chainspec devnet

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

✅ Chainspec rebuild complete! Changes have been committed.

@m2ux
Copy link
Contributor Author

m2ux commented Mar 4, 2026

/bot cargo-fmt

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

✅ Cargo format complete. No changes detected.

@m2ux
Copy link
Contributor Author

m2ux commented Mar 4, 2026

/bot fix-metadata-conflicts

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

❌ Failed to fix metadata conflicts. Check the workflow logs for details.

@m2ux
Copy link
Contributor Author

m2ux commented Mar 4, 2026

/bot fix-metadata-conflicts accept-current

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

ℹ️ No conflicts detected between this PR and the main branch.

Copy link
Contributor

@ozgb ozgb left a comment

Choose a reason for hiding this comment

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

Looks good! chainspec changes need reverting before merge

Copy link
Contributor

Choose a reason for hiding this comment

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

The chainspec files need reverting here

@m2ux m2ux enabled auto-merge March 5, 2026 09:04
@m2ux m2ux changed the title fix(ci): bot workflow TOCTOU and execution hardening [PM-22117] ci: bot workflow TOCTOU and execution hardening [PM-22117] Mar 6, 2026
@m2ux m2ux requested a review from ozgb March 6, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants