Skip to content

🐛 detect toJSON(github.event) in Dangerous-Workflow check#4898

Merged
spencerschrock merged 3 commits intoossf:mainfrom
heathdutton:fix/3554-dangerous-workflow-tojson
Jan 9, 2026
Merged

🐛 detect toJSON(github.event) in Dangerous-Workflow check#4898
spencerschrock merged 3 commits intoossf:mainfrom
heathdutton:fix/3554-dangerous-workflow-tojson

Conversation

@heathdutton
Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

The Dangerous-Workflow check does not detect script injection vulnerabilities when toJSON(github.event) or toJSON(github) is used in workflow run steps. These serialize the entire event/context object which contains attacker-controlled data.

What is the new behavior (if this is a feature change)?

The check now detects toJSON(github.event) and toJSON(github) patterns as dangerous, including case variations and whitespace.

  • Tests for the changes have been added (for bug fixes/features)

Which issue(s) this PR fixes

Fixes #3554

Special notes for your reviewer

The regex (?i)tojson\s*\(\s*github(\s*\)|\.event) matches:

  • toJSON(github) - serializes entire context including event
  • toJSON(github.event) and toJSON(github.event.*) - serializes event data
  • Case insensitive and handles whitespace

It correctly ignores safe patterns like toJSON(github.repository).

Does this PR introduce a user-facing change?

Dangerous-Workflow check now detects toJSON(github.event) and toJSON(github) as dangerous patterns

Signed-off-by: Heath Dutton🕴️ <heathdutton@gmail.com>
@heathdutton heathdutton requested a review from a team as a code owner December 31, 2025 17:32
@heathdutton heathdutton requested review from justaugustus and raghavkaul and removed request for a team December 31, 2025 17:32
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Dec 31, 2025
Copy link
Copy Markdown
Member

@spencerschrock spencerschrock left a comment

Choose a reason for hiding this comment

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

I think if we just focus on toJSON(github) and to.JSON(github.event) (and not any other subfields) we avoid false positives for now, while we think of how to get the specificity right.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.70%. Comparing base (353ed60) to head (240a790).
⚠️ Report is 303 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4898      +/-   ##
==========================================
+ Coverage   66.80%   69.70%   +2.90%     
==========================================
  Files         230      251      +21     
  Lines       16602    15652     -950     
==========================================
- Hits        11091    10911     -180     
+ Misses       4808     3867     -941     
- Partials      703      874     +171     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Heath Dutton🕴️ <heathdutton@gmail.com>
@spencerschrock
Copy link
Copy Markdown
Member

/scdiff generate Dangerous-Workflow

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 9, 2026

@spencerschrock spencerschrock enabled auto-merge (squash) January 9, 2026 21:32
@spencerschrock spencerschrock merged commit 85483c2 into ossf:main Jan 9, 2026
37 checks passed
thomasleplus pushed a commit to thomasleplus/scorecard that referenced this pull request Mar 8, 2026
* 🐛 detect toJSON(github.event) in Dangerous-Workflow check

Signed-off-by: Heath Dutton🕴️ <heathdutton@gmail.com>

* address review: only match exact toJSON(github) and toJSON(github.event)

Signed-off-by: Heath Dutton🕴️ <heathdutton@gmail.com>

---------

Signed-off-by: Heath Dutton🕴️ <heathdutton@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

BUG: Dangerous-Workflow doesn't trigger on toJSON(github.event)

2 participants