Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.1k
Actions: ActorIfCheckControlCheck model fix for events that don't populate the checked field#22368
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
Merged
jketema
merged 5 commits into
github:main
from
computersarebad:actor-if-check-event-validityAug 19, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9251d21
Actions: ActorIfCheck should not protect events that do not populate …
computersarebad 3048f47
Split payload-field actor checks into EventActorIfCheck
computersarebad e9d9d3a
Simplify EventActorIfCheck by binding context_prefix as a field
computersarebad dc6ee11
Add test coverage for sender, head_commit and commits checks
computersarebad 0a376e8
Split change note into breaking and minorAnalysis notes
computersarebad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4 actions/ql/lib/change-notes/2026-08-17-actor-if-check-event-validity.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * Checks on actor fields read from the event payload (e.g. `github.event.pull_request.user.login`) now only count as protection for events whose payload actually populates that field. Previously, a condition such as `github.event.pull_request.user.login != 'name'` on a workflow triggered by `issues` events was treated as a protective check even though `github.event.pull_request` is not populated for `issues` events, which makes the condition vacuous. This change may result in more alerts for queries using the `ControlCheck` class. |
4 changes: 4 additions & 0 deletions
4 actions/ql/lib/change-notes/2026-08-18-split-event-actor-if-check.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: breaking | ||
| --- | ||
| * Checks on actor fields read from the event payload (e.g. `github.event.pull_request.user.login`) were split out of `ActorIfCheck` into a new class `EventActorIfCheck`. The `ActorIfCheck` class now only covers `github.actor` and `github.triggering_actor`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -314,17 +314,6 @@ class LabelIfCheck extends LabelCheck instanceof If { | ||
| class ActorIfCheck extends ActorCheck instanceof If { | ||
| ActorIfCheck() { | ||
| // eg: github.event.pull_request.user.login == 'admin' | ||
| exists( | ||
| normalizeExpr(this.getCondition()) | ||
| .regexpFind([ | ||
| "\\bgithub\\.event\\.pull_request\\.user\\.login\\b", | ||
| "\\bgithub\\.event\\.head_commit\\.author\\.name\\b", | ||
| "\\bgithub\\.event\\.commits.*\\.author\\.name\\b", | ||
| "\\bgithub\\.event\\.sender\\.login\\b" | ||
| ], _, _) | ||
| ) | ||
| or | ||
| // eg: github.actor == 'admin' | ||
| // eg: github.triggering_actor == 'admin' | ||
| exists( | ||
| @@ -335,6 +324,51 @@ class ActorIfCheck extends ActorCheck instanceof If { | ||
| } | ||
| } | ||
| /** | ||
| * Gets a regular expression matching a condition on an actor field that is | ||
| * only populated for events whose payload contains the `context_prefix` context. | ||
| */ | ||
| private string eventPayloadActorFieldRegex(string context_prefix) { | ||
| context_prefix = "github.event.pull_request" and | ||
| result = "\\bgithub\\.event\\.pull_request\\.user\\.login\\b" | ||
| or | ||
| context_prefix = "github.event.head_commit" and | ||
| result = "\\bgithub\\.event\\.head_commit\\.author\\.name\\b" | ||
| or | ||
| context_prefix = "github.event.commits" and | ||
| result = "\\bgithub\\.event\\.commits.*\\.author\\.name\\b" | ||
| or | ||
| context_prefix = "github.event.sender" and | ||
| result = "\\bgithub\\.event\\.sender\\.login\\b" | ||
| } | ||
| /** An If node that checks an actor field from the event payload */ | ||
| class EventActorIfCheck extends ActorCheck instanceof If { | ||
| string context_prefix; | ||
| EventActorIfCheck() { | ||
| // eg: github.event.pull_request.user.login == 'admin' | ||
| exists( | ||
| normalizeExpr(this.getCondition()) | ||
| .regexpFind(eventPayloadActorFieldRegex(context_prefix), _, _) | ||
| ) | ||
| } | ||
| override predicate protectsCategoryAndEvent(string category, string event) { | ||
| ActorCheck.super.protectsCategoryAndEvent(category, event) and | ||
| ( | ||
| // the `sender` object is part of every webhook event payload | ||
| context_prefix = "github.event.sender" | ||
| or | ||
| // other actor fields only restrict events whose payload populates them. | ||
| // eg: `github.event.pull_request.user.login` cannot restrict the actor | ||
| // of an `issues` event since `github.event.pull_request` is not | ||
| // populated there, which makes the condition vacuous | ||
| contextTriggerDataModel(event, context_prefix) | ||
| ) | ||
| } | ||
| } | ||
computersarebad marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| class PullRequestTargetRepositoryIfCheck extends RepositoryCheck instanceof If { | ||
| PullRequestTargetRepositoryIfCheck() { | ||
| // eg: github.event.pull_request.head.repo.full_name == github.repository | ||
12 changes: 12 additions & 0 deletions
12 actions/ql/test/query-tests/Security/CWE-094/.github/workflows/actor_check_valid_event.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| on: | ||
| pull_request_target: | ||
| types: [opened] | ||
| jobs: | ||
| # The `if:` condition checks an actor field that is populated for | ||
| # `pull_request_target` events, so the injectable step is protected. | ||
| valid-actor-check: | ||
| runs-on: ubuntu-latest | ||
| if: github.event.pull_request.user.login == 'trusted-user' | ||
| steps: | ||
| - run: echo '${{ github.event.pull_request.title }}' |
46 changes: 46 additions & 0 deletions
46 actions/ql/test/query-tests/Security/CWE-094/.github/workflows/actor_check_wrong_event.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| on: | ||
| issues: | ||
| types: [opened] | ||
| jobs: | ||
| # The `if:` condition compares an actor field that is never populated for | ||
| # `issues` events, so it is always true and does not protect the injectable step. | ||
| vacuous-actor-check: | ||
| runs-on: ubuntu-latest | ||
| if: github.event.pull_request.user.login != 'some-bot[bot]' | ||
| steps: | ||
| - run: echo '${{ github.event.issue.title }}' | ||
| # The `if:` condition checks an actor context that is populated for every | ||
| # event, so the injectable step is protected. | ||
| valid-actor-check: | ||
| runs-on: ubuntu-latest | ||
| if: github.actor == 'trusted-user' | ||
| steps: | ||
| - run: echo '${{ github.event.issue.title }}' | ||
| # The `sender` object is part of every webhook event payload, so this | ||
| # check is effective and the injectable step is protected. | ||
| valid-sender-check: | ||
| runs-on: ubuntu-latest | ||
| if: github.event.sender.login == 'trusted-user' | ||
| steps: | ||
| - run: echo '${{ github.event.issue.title }}' | ||
| # `github.event.head_commit` is only populated for `push` events, so this | ||
| # condition is always true for `issues` events and does not protect the | ||
| # injectable step. | ||
| vacuous-head-commit-check: | ||
| runs-on: ubuntu-latest | ||
| if: github.event.head_commit.author.name != 'some-bot' | ||
| steps: | ||
| - run: echo '${{ github.event.issue.title }}' | ||
| # `github.event.commits` is only populated for `push` events, so this | ||
| # condition is always true for `issues` events and does not protect the | ||
| # injectable step. | ||
| vacuous-commits-check: | ||
| runs-on: ubuntu-latest | ||
| if: github.event.commits[0].author.name != 'some-bot' | ||
| steps: | ||
| - run: echo '${{ github.event.issue.title }}' |
9 changes: 9 additions & 0 deletions
9 actions/ql/test/query-tests/Security/CWE-094/CodeInjectionCritical.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9 actions/ql/test/query-tests/Security/CWE-094/CodeInjectionMedium.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.