Skip to content

[Security] Fix TOCTOU race in style-bot-action workflow#4183

Merged
paulinebm merged 1 commit into
mainfrom
fix/style-bot-toctou
May 7, 2026
Merged

[Security] Fix TOCTOU race in style-bot-action workflow#4183
paulinebm merged 1 commit into
mainfrom
fix/style-bot-toctou

Conversation

@paulinebm

@paulinebm paulinebm commented May 4, 2026

Copy link
Copy Markdown
Contributor

Note

Medium Risk
Medium risk because it restructures the style-bot GitHub Actions workflow, changing how code is checked out and how credentials are generated/passed for pushing fixes, which could break automation or alter permissions if misconfigured.

Overview
Hardens the style-bot-action reusable workflow against TOCTOU attacks when running on PRs. It now pins execution to the PR headSha, verifies the SHA before running untrusted code and again before pushing, and replaces the previous timestamp-based git checks with a server-side pushedDate check.

Separates untrusted formatting from trusted push steps. The style run exports any changes as a binary patch artifact, and a new push-style-fixes job downloads/applies that patch and pushes using a short-lived GitHub App token (app_id/app_private_key) with tightened job permissions.

Reviewed by Cursor Bugbot for commit 42642d4. Bugbot is set up for automated code reviews on this repo. Configure here.

@paulinebm paulinebm requested review from Wauplin and hanouticelina May 4, 2026 13:05
Comment thread .github/workflows/style-bot-action.yml
@bot-ci-comment

bot-ci-comment Bot commented May 4, 2026

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

paulinebm added a commit that referenced this pull request May 4, 2026
Replace `git log --format=%cd` with GitHub Events API push timestamp
(server-side, not forgeable). Falls back to API commit date if push
event not in recent history. Fixes Cursor Bugbot finding on PR #4183.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@paulinebm

Copy link
Copy Markdown
Contributor Author

@cursor review

Comment thread .github/workflows/style-bot-action.yml Outdated
@paulinebm paulinebm closed this May 4, 2026
@paulinebm paulinebm reopened this May 4, 2026
@paulinebm paulinebm marked this pull request as draft May 4, 2026 15:09
@paulinebm

Copy link
Copy Markdown
Contributor Author

@cursor review

Comment thread .github/workflows/style-bot-action.yml Outdated
@paulinebm

Copy link
Copy Markdown
Contributor Author

@cursor review

Comment thread .github/workflows/style-bot-action.yml
@paulinebm

Copy link
Copy Markdown
Contributor Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 9aff1d5. Configure here.

@paulinebm paulinebm marked this pull request as ready for review May 5, 2026 08:05
@paulinebm paulinebm marked this pull request as draft May 5, 2026 08:05
@paulinebm

Copy link
Copy Markdown
Contributor Author

@cursor review

Comment thread .github/workflows/style-bot-action.yml
Comment thread .github/workflows/style-bot-action.yml Outdated
Comment thread .github/workflows/style-bot-action.yml Outdated
@paulinebm

Copy link
Copy Markdown
Contributor Author

@cursor review

Comment thread .github/workflows/style-bot-action.yml Outdated
@paulinebm

Copy link
Copy Markdown
Contributor Author

@cursor review

Comment thread .github/workflows/style-bot-action.yml Dismissed
Comment thread .github/workflows/style-bot-action.yml Dismissed

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 4dff5f4. Configure here.

@paulinebm paulinebm force-pushed the fix/style-bot-toctou branch from 4dff5f4 to d5303fd Compare May 5, 2026 09:53
@paulinebm

Copy link
Copy Markdown
Contributor Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d5303fd. Configure here.

@paulinebm

Copy link
Copy Markdown
Contributor Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a070611. Configure here.

@paulinebm paulinebm marked this pull request as ready for review May 5, 2026 12:41
@paulinebm paulinebm force-pushed the fix/style-bot-toctou branch from a070611 to d87e6e6 Compare May 5, 2026 12:46
@huggingface huggingface deleted a comment from cursor Bot May 5, 2026
@paulinebm paulinebm force-pushed the fix/style-bot-toctou branch from b85b288 to ed9b560 Compare May 5, 2026 14:06
Comment thread .github/workflows/style-bot-action.yml
Comment thread .github/workflows/style-bot-action.yml Outdated
@paulinebm paulinebm force-pushed the fix/style-bot-toctou branch from 7bf2506 to db5c4b2 Compare May 5, 2026 14:54
Comment thread .github/workflows/style-bot-action.yml Outdated
@paulinebm paulinebm force-pushed the fix/style-bot-toctou branch 3 times, most recently from a6cc91a to bf6d1ba Compare May 5, 2026 15:30
@huggingface huggingface deleted a comment from cursor Bot May 5, 2026
@paulinebm paulinebm force-pushed the fix/style-bot-toctou branch from bf6d1ba to 42642d4 Compare May 5, 2026 15:43

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 42642d4. Configure here.

description: "GitHub App ID used to generate a short-lived token"
app_private_key:
required: true
description: "GitHub App private key used to generate a short-lived token"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caller workflow passes removed secret, missing required secrets

High Severity

The style-bot-action.yml reusable workflow now requires app_id and app_private_key secrets instead of bot_token. The calling workflow, style-bot.yml, still passes bot_token, leading to immediate failures as GitHub Actions rejects undeclared or missing required secrets.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 42642d4. Configure here.

@paulinebm paulinebm merged commit e2867e9 into main May 7, 2026
21 checks passed
@paulinebm paulinebm deleted the fix/style-bot-toctou branch May 7, 2026 11:54
paulinebm added a commit to huggingface/optimum-onnx that referenced this pull request May 7, 2026
## Summary

- Bumps the pinned SHA of the reusable `style-bot-action.yml` workflow
to the hardened version
([huggingface/huggingface_hub#4183](huggingface/huggingface_hub#4183))
- Switches from static PAT (`HF_STYLE_BOT_ACTION`) to GitHub App
short-lived tokens (`HF_BOT_STYLE_APP_ID` + `HF_BOT_STYLE_SECRET_PEM`)
- Drops `contents: write` (push is now handled inside the reusable
workflow via the app token)

⚠️ Requires `HF_BOT_STYLE_APP_ID` and `HF_BOT_STYLE_SECRET_PEM` secrets
to be set in this repo's settings.
@Wauplin

Wauplin commented May 7, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

@huggingface-hub-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v1.15.0 release.

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.

4 participants