Skip to content

Commit 1233d81

Browse files
committed
Improve actions/ql/src/Security/CWE-829/UntrustedCheckoutX queries
1 parent fb0ee5b commit 1233d81

File tree

8 files changed

+27
-13
lines changed

8 files changed

+27
-13
lines changed

actions/ql/lib/ext/config/poisonable_steps.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extensions:
7070
- ["(source|sh|bash|zsh|fish)\\s+([^\\s]+)\\b", 2]
7171
- ["(node)\\s+([^\\s]+)(\\.js|\\.ts)\\b", 2]
7272
- ["(python[\\d\\.]*)\\s+([^\\s]+)\\.py\\b", 2]
73+
- ["(python[\\d\\.]*)\\s+([\\-m]+)\\s+(\\w+)\\b", 2] # eg: pythonX -m anything(dir or file)
7374
- ["(ruby)\\s+([^\\s]+)\\.rb\\b", 2]
74-
- ["(go)\\s+(generate|run)\\s+([^\\s]+)\\.go\\b", 3]
75+
- ["(go)\\s+(generate|run)\\s+([^\\s]+)", 3]
7576
- ["(dotnet)\\s+([^\\s]+)\\.csproj\\b", 2]
76-

actions/ql/src/Security/CWE-094/CodeInjectionMedium.ql

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name Code injection
33
* @description Interpreting unsanitized user input as code allows a malicious user to perform arbitrary
44
* code execution.
5-
* @kind path-problem
5+
* @ kind path-problem
66
* @problem.severity warning
77
* @security-severity 5.0
88
* @precision medium
@@ -18,8 +18,13 @@ import actions
1818
import codeql.actions.security.CodeInjectionQuery
1919
import CodeInjectionFlow::PathGraph
2020

21-
from CodeInjectionFlow::PathNode source, CodeInjectionFlow::PathNode sink
22-
where mediumSeverityCodeInjection(source, sink)
23-
select sink.getNode(), source, sink,
24-
"Potential code injection in $@, which may be controlled by an external user.", sink,
25-
sink.getNode().asExpr().(Expression).getRawExpression()
21+
// from CodeInjectionFlow::PathNode source, CodeInjectionFlow::PathNode sink
22+
// where mediumSeverityCodeInjection(source, sink)
23+
// select sink.getNode(), source, sink,
24+
// "Potential code injection in $@, which may be controlled by an external user.", sink,
25+
// sink.getNode().asExpr().(Expression).getRawExpression()
26+
from string test
27+
where
28+
test.regexpMatch("(python[\\d\\.]*)\\s+([^\\s]+)\\.py\\b") and
29+
test = "python -m dir" //go run main/main.go //go run .
30+
select test

actions/ql/src/Security/CWE-829/UntrustedCheckoutCritical.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Overview
22

3-
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 triggers such as `pull_request_target` or `issue_comment` followed by an explicit checkout of untrusted code (Pull Request HEAD) may lead to repository compromise if untrusted code gets executed (e.g., due to a modified build script) in a privileged job.
3+
GitHub workflows can be triggered through various repository events, including incoming pull requests (PRs) or comments on Issues/PRs. A dangerous misuse of event triggers such as `pull_request_target` or `issue_comment` followed by an explicit checkout of untrusted input from the PR may lead to repository compromise if untrusted code gets executed in a privileged job. Untrusted code may get executed due to a modified build script, workflow injection, or registry hijacking. **Carefully review** whether least privileges is used and whether input is taken from untrusted sources.
44

55
## Recommendation
66

@@ -133,3 +133,4 @@ jobs:
133133
## References
134134
135135
- GitHub Security Lab Research: [Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/).
136+
- Living Off the Pipeline: [LOTP](https://boostsecurityio.github.io/lotp/).

actions/ql/src/Security/CWE-829/UntrustedCheckoutCritical.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ where
5151
event.getName() = checkoutTriggers() and
5252
not exists(ControlCheck check | check.protects(checkout, event, "untrusted-checkout")) and
5353
not exists(ControlCheck check | check.protects(poisonable, event, "untrusted-checkout"))
54-
select poisonable, checkout, poisonable,
54+
select checkout, checkout, poisonable,
5555
"Potential execution of untrusted code on a privileged workflow ($@)", event, event.getName()

actions/ql/src/Security/CWE-829/UntrustedCheckoutHigh.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Overview
22

3-
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 triggers such as `pull_request_target` or `issue_comment` followed by an explicit checkout of untrusted code (Pull Request HEAD) may lead to repository compromise if untrusted code gets executed (e.g., due to a modified build script) in a privileged job.
3+
GitHub workflows can be triggered through various repository events, including incoming pull requests (PRs) or comments on Issues/PRs. A dangerous misuse of event triggers such as `pull_request_target` or `issue_comment` followed by an explicit checkout of untrusted input from the PR may lead to repository compromise if untrusted code gets executed in a privileged job. Untrusted code may get executed due to a modified build script, workflow injection, or registry hijacking. **Carefully review** whether least privileges is used and whether input is taken from untrusted sources.
44

55
## Recommendation
66

@@ -133,3 +133,4 @@ jobs:
133133
## References
134134
135135
- GitHub Security Lab Research: [Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/).
136+
- Living Off the Pipeline: [LOTP](https://boostsecurityio.github.io/lotp/).

actions/ql/src/Security/CWE-829/UntrustedCheckoutHigh.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @name Checkout of untrusted code in trusted context
2+
* @name Checkout of untrusted code in privileged context without privileged context use
33
* @description Privileged workflows have read/write access to the base repository and access to secrets.
44
* By explicitly checking out and running the build script from a fork the untrusted code is running in an environment
55
* that is able to push to the base repository and to access secrets.

actions/ql/src/Security/CWE-829/UntrustedCheckoutMedium.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Overview
22

3-
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 triggers such as `pull_request_target` or `issue_comment` followed by an explicit checkout of untrusted code (Pull Request HEAD) may lead to repository compromise if untrusted code gets executed (e.g., due to a modified build script) in a privileged job.
3+
GitHub workflows can be triggered through various repository events, including incoming pull requests (PRs) or comments on Issues/PRs. A dangerous misuse of event triggers such as `pull_request_target` or `issue_comment` followed by an explicit checkout of untrusted input from the PR may lead to repository compromise if untrusted code gets executed in a privileged job. Untrusted code may get executed due to a modified build script, workflow injection, or registry hijacking. **Carefully review** whether least privileges is used and whether input is taken from untrusted sources.
44

55
## Recommendation
66

@@ -133,3 +133,4 @@ jobs:
133133
## References
134134
135135
- GitHub Security Lab Research: [Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/).
136+
- Living Off the Pipeline: [LOTP](https://boostsecurityio.github.io/lotp/).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: majorAnalysis
3+
---
4+
* Fixed help file descriptions for queries: `actions/untrusted-checkout/critical`, `actions/untrusted-checkout/high`, `actions/untrusted-checkout/medium`. Previously the messages were unclear as to why and how the vulnerabilities could occur. Additionally alter 2 patterns in the detection such that now extra sinks are detected in the following cases: scripts executed via python modules and `go run` in directories are detected as potential mechanisms of injection. This may lead to more results being detected by all 3 queries.
5+
* Adjusted `actions/untrusted-checkout/critical` to align more with other untrusted resource queries, where the alert location is the location where the artifact is obtained from (the checkout point). This aligns with the other 2 related queries. This will cause the same alerts to re-open for closed alerts of this query.
6+
* Adjusted the name of `actions/untrusted-checkout/high` to more clearly describe which parts of the scenario are in a privileged context. This will cause the same alerts to re-open for closed alerts of this query.

0 commit comments

Comments
 (0)