-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Sequester issue_comment triggered untrusted checkout from other triggers #18838
Open
KyFaSt
wants to merge
5
commits into
github:main
Choose a base branch
from
KyFaSt:kyfast/untrusted-checkout-refinements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
01afda8
sequester issue_comment triggered untrusted checkout from other triggers
KyFaSt 2368979
remove unused predicate
KyFaSt 3b5d8b5
rename test
KyFaSt e343646
fix id typos
KyFaSt 67a9c25
Merge branch 'main' into kyfast/untrusted-checkout-refinements
KyFaSt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
14 changes: 14 additions & 0 deletions
14
actions/ql/src/Security/CWE-829/UntrustedCheckoutIssueCommentCritical.md
This file contains 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,14 @@ | ||
# Execution of Untrusted Checked-out Code Triggered by Issue Comment | ||
|
||
## Description | ||
|
||
GitHub workflows can be triggered through various repository events, including incoming pull requests (PRs) or comments on Issues/PRs. A potentially dangerous misuse of the the trigger `issue_comment` followed by an explicit checkout of untrusted code (Pull Request HEAD) may lead to repository compromise if untrusted code gets executed in a privileged job. | ||
|
||
## Recommendations | ||
|
||
- Avoid using `issue_comment` unless necessary, consider using label gates instead to trigger workflows. | ||
- If you must use `issue_comment` to trigger workflow runs, consider limiting the token that forked repos can use to read-only access to the repository or disallowing forks entirely. | ||
|
||
Issue comment triggers are vulnerable to abuse by malicious actors. Triggering workflow run that checkout code through `issue_comment` can allow a malicious actor to execute code in the time between a comment being posted and the workflow run being triggered. Issue comment events are also not subject to the same security checks or pull request approvals that `pull_request` events are. | ||
|
||
- [How to Secure your GitHub Actions Workflows with CodeQL](https://github.blog/security/application-security/how-to-secure-your-github-actions-workflows-with-codeql/#issueoops-security-pitfalls-with-issue_comment-trigger) |
55 changes: 55 additions & 0 deletions
55
actions/ql/src/Security/CWE-829/UntrustedCheckoutIssueCommentCritical.ql
This file contains 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,55 @@ | ||
/** | ||
* @name Checkout of untrusted code in trusted context | ||
* @description Privileged workflows have read/write access to the base repository and access to secrets. | ||
* By explicitly checking out and running the build script from a fork the untrusted code is running in an environment | ||
* that is able to push to the base repository and to access secrets. | ||
* @kind path-problem | ||
* @problem.severity warning | ||
* @precision high | ||
* @security-severity 7.5 | ||
* @id actions/untrusted-checkout-issue-comment/critical | ||
* @tags actions | ||
* security | ||
* external/cwe/cwe-829 | ||
*/ | ||
|
||
import actions | ||
import codeql.actions.security.UntrustedCheckoutQuery | ||
import codeql.actions.security.PoisonableSteps | ||
import codeql.actions.security.ControlChecks | ||
|
||
query predicate edges(Step a, Step b) { a.getNextStep() = b } | ||
|
||
from PRHeadCheckoutStep checkout, PoisonableStep poisonable, Event event | ||
where | ||
// the checkout is followed by a known poisonable step | ||
checkout.getAFollowingStep() = poisonable and | ||
( | ||
poisonable instanceof Run and | ||
( | ||
// Check if the poisonable step is a local script execution step | ||
// and the path of the command or script matches the path of the downloaded artifact | ||
isSubpath(poisonable.(LocalScriptExecutionRunStep).getPath(), checkout.getPath()) | ||
or | ||
// Checking the path for non local script execution steps is very difficult | ||
not poisonable instanceof LocalScriptExecutionRunStep | ||
// Its not easy to extract the path from a non-local script execution step so skipping this check for now | ||
// and isSubpath(poisonable.(Run).getWorkingDirectory(), checkout.getPath()) | ||
) | ||
or | ||
poisonable instanceof UsesStep and | ||
( | ||
not poisonable instanceof LocalActionUsesStep and | ||
checkout.getPath() = "GITHUB_WORKSPACE/" | ||
or | ||
isSubpath(poisonable.(LocalActionUsesStep).getPath(), checkout.getPath()) | ||
) | ||
) and | ||
// the checkout occurs in a privileged context | ||
inPrivilegedContext(poisonable, event) and | ||
inPrivilegedContext(checkout, event) and | ||
event.getName() = issueCommentTriggers() and | ||
not exists(ControlCheck check | check.protects(checkout, event, "untrusted-checkout")) and | ||
not exists(ControlCheck check | check.protects(poisonable, event, "untrusted-checkout")) | ||
select poisonable, checkout, poisonable, | ||
"Potential execution of untrusted code on a privileged workflow ($@)", event, event.getName() | ||
Check warning Code scanning / CodeQL Alert message style violation Warning
Alert message should end with a full stop.
|
14 changes: 14 additions & 0 deletions
14
actions/ql/src/Security/CWE-829/UntrustedCheckoutIssueCommentHigh.md
This file contains 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,14 @@ | ||
# Execution of Untrusted Checked-out Code Triggered by Issue Comment | ||
|
||
## Description | ||
|
||
GitHub workflows can be triggered through various repository events, including incoming pull requests (PRs) or comments on Issues/PRs. A potentially dangerous misuse of the the trigger `issue_comment` followed by an explicit checkout of untrusted code (Pull Request HEAD) may lead to repository compromise if untrusted code gets executed in a privileged job. | ||
|
||
## Recommendations | ||
|
||
- Avoid using `issue_comment` unless necessary, consider using label gates instead to trigger workflows. | ||
- If you must use `issue_comment` to trigger workflow runs, consider limiting the token that forked repos can use to read-only access to the repository or disallowing forks entirely. | ||
|
||
Issue comment triggers are vulnerable to abuse by malicious actors. Triggering workflow run that checkout code through `issue_comment` can allow a malicious actor to execute code in the time between a comment being posted and the workflow run being triggered. Issue comment events are also not subject to the same security checks or pull request approvals that `pull_request` events are. | ||
|
||
- [How to Secure your GitHub Actions Workflows with CodeQL](https://github.blog/security/application-security/how-to-secure-your-github-actions-workflows-with-codeql/#issueoops-security-pitfalls-with-issue_comment-trigger) |
30 changes: 30 additions & 0 deletions
30
actions/ql/src/Security/CWE-829/UntrustedCheckoutIssueCommentHigh.ql
This file contains 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,30 @@ | ||
/** | ||
* @name Checkout of untrusted code in trusted context | ||
* @description Privileged workflows have read/write access to the base repository and access to secrets. | ||
* By explicitly checking out and running the build script from a fork the untrusted code is running in an environment | ||
* that is able to push to the base repository and to access secrets. | ||
* @kind problem | ||
* @problem.severity warning | ||
* @precision high | ||
* @security-severity 7.5 | ||
* @id actions/untrusted-checkout-issue-comment/high | ||
* @tags actions | ||
* security | ||
* external/cwe/cwe-829 | ||
*/ | ||
|
||
import actions | ||
import codeql.actions.security.UntrustedCheckoutQuery | ||
import codeql.actions.security.PoisonableSteps | ||
import codeql.actions.security.ControlChecks | ||
|
||
from PRHeadCheckoutStep checkout, Event event | ||
where | ||
// the checkout is NOT followed by a known poisonable step | ||
not checkout.getAFollowingStep() instanceof PoisonableStep and | ||
// the checkout occurs in a privileged context | ||
inPrivilegedContext(checkout, event) and | ||
event.getName() = issueCommentTriggers() and | ||
not exists(ControlCheck check | check.protects(checkout, event, "untrusted-checkout")) | ||
select checkout, "Potential execution of untrusted code on a privileged workflow ($@)", event, | ||
Check warning Code scanning / CodeQL Alert message style violation Warning
Alert message should end with a full stop.
|
||
event.getName() |
Oops, something went wrong.
Oops, something went wrong.
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.
Check warning
Code scanning / CodeQL
Singleton set literal Warning