Skip to content

Commit 8231261

Browse files
author
Alvaro Muñoz
committed
New poisonable steps
1 parent 59fd853 commit 8231261

File tree

5 files changed

+283
-109
lines changed

5 files changed

+283
-109
lines changed

ql/lib/codeql/actions/security/PoisonableSteps.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ class PoisonableCommandStep extends PoisonableStep, Run {
1818
PoisonableCommandStep() {
1919
exists(string regexp |
2020
poisonableCommandsDataModel(regexp) and
21-
exists(this.getScript().splitAt("\n").trim().regexpFind("(^|\\b|\\s+)" + regexp, _, _))
21+
exists(
22+
this.getScript()
23+
.splitAt("\n")
24+
.trim()
25+
.regexpFind("(^|\\b|\\s+)" + regexp + "(\\s|;|\\||\\)|`|-|&&|[a-zA-Z]|$)", _, _)
26+
)
2227
)
2328
}
2429
}
@@ -41,7 +46,6 @@ class LocalScriptExecutionRunStep extends PoisonableStep, Run {
4146
LocalScriptExecutionRunStep() {
4247
exists(string line, string regexp, int group | line = this.getScript().splitAt("\n").trim() |
4348
poisonableLocalScriptsDataModel(regexp, group) and
44-
//cmd = line.regexpCapture(".*(^|\\b|\\s+|\\$\\(|`)" + regexp + "(\\b|\\s+|;|\\)|`|$).*", group)
4549
cmd =
4650
line.regexpCapture(".*(^|;|\\$\\(|`|\\||&&)\\s*" + regexp + "\\s*(;|\\||\\)|`|-|&&|$).*",
4751
group)

ql/lib/ext/config/poisonable_steps.yml

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ extensions:
22
- addsTo:
33
pack: github/actions-all
44
extensible: poisonableActionsDataModel
5-
# source: https://github.com/boostsecurityio/poutine/blob/main/opa/rego/rules/untrusted_checkout_exec.rego#L16
65
# source: https://boostsecurityio.github.io/lotp/
76
data:
87
- ["pre-commit/action"]
@@ -14,40 +13,46 @@ extensions:
1413
- addsTo:
1514
pack: github/actions-all
1615
extensible: poisonableCommandsDataModel
17-
# source: https://github.com/boostsecurityio/poutine/blob/main/opa/rego/rules/untrusted_checkout_exec.rego#L23
1816
# source: https://boostsecurityio.github.io/lotp/
1917
data:
20-
- ["ant "]
21-
- ["bundle "]
22-
- ["cargo "]
23-
- ["checkov "]
24-
- ["eslint "]
25-
- ["go generate"]
26-
- ["go run"]
27-
- ["gomplate "]
28-
- ["gradle "]
29-
- ["java -jar"]
30-
- ["make "]
18+
- ["ant"]
19+
- ["awk\\s+-f"]
20+
- ["bundle"]
21+
- ["cargo"]
22+
- ["checkov"]
23+
- ["eslint"]
24+
- ["gcloud\\s+builds submit"]
25+
- ["golangci-lint"]
26+
- ["gomplate"]
27+
- ["goreleaser"]
28+
- ["gradle"]
29+
- ["java\\s+-jar"]
30+
- ["make"]
31+
- ["mdformat"]
3132
- ["mkdocs"]
3233
- ["msbuild"]
3334
- ["mvn"]
3435
- ["mypy"]
35-
- ["npm [a-z]"]
36-
- ["pnpm [a-z]"]
36+
- ["(p)?npm\\s+[a-z]"]
3737
- ["pre-commit"]
3838
- ["prettier"]
39-
- ["pip install -r"]
40-
- ["pip install --requirement"]
39+
- ["phpstan"]
40+
- ["pip\\s+install\\s+-r"]
41+
- ["pip\\s+install\\s+--requirement"]
4142
- ["poetry"]
4243
- ["pylint"]
4344
- ["pytest"]
44-
- ["rake "]
45-
- ["rails db:create"]
46-
- ["rails assets:precompile"]
47-
- ["rubocop "]
48-
- ["terraform "]
45+
- ["rake"]
46+
- ["rails\\s+db:create"]
47+
- ["rails\\s+assets:precompile"]
48+
- ["rubocop"]
49+
- ["sed\\s+-e"]
50+
- ["sed\\s+-f"]
51+
- ["stylelint"]
52+
- ["terraform"]
4953
- ["tflint"]
50-
- ["yarn "]
54+
- ["yarn"]
55+
- ["webpack"]
5156
- addsTo:
5257
pack: github/actions-all
5358
extensible: poisonableLocalScriptsDataModel
@@ -59,5 +64,6 @@ extensions:
5964
- ["(node)\\s+(.*)(\\.js|\\.ts)", 3]
6065
- ["(python)\\s+(.*)\\.py", 3]
6166
- ["(ruby)\\s+(.*)\\.rb", 3]
62-
- ["(go)\\s+(.*)\\.go", 3]
67+
- ["(go)\\s+(generate|run)\\s+(.*)\\.go", 4]
68+
- ["(dotnet)\\s+(.*)\\.csproj", 3]
6369

ql/test/library-tests/.github/workflows/poisonable_steps.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,14 @@ jobs:
2727
- run: ruby scripts/generate_theme.rb --outfile js/storybook/theme.css
2828
- run: bundle run exec ruby scripts/generate_theme.rb --outfile js/storybook/theme.css
2929
- run: xvfb-run ./mvnw clean package
30+
- run: echo "foo" && npm i && echo "bar"
31+
- run: echo "foo" | npm i | echo "bar"
32+
- run: echo "foo" | npm i | echo "bar"
33+
- run: echo "foo `npm i` bar"
34+
- run: dotnet test foo/Tests.csproj -c Release
35+
- run: go run foo.go
36+
- run: sed -i "s|git_branch = .*|git_branch = \"$GITHUB_HEAD_REF\"|" config.json # not supported yet
37+
- run: sed -f ./config.sed file.txt > foo.txt
38+
- run: sed -f config file.txt > foo.txt
39+
- run: echo "foo" | awk -f ./config.awk > foo.txt
40+
- run: gcloud builds submit --quiet --substitutions="COMMIT_SHA=foo

ql/test/library-tests/poisonable_steps.expected

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,14 @@
1717
| .github/workflows/poisonable_steps.yml:26:9:27:6 | Run Step |
1818
| .github/workflows/poisonable_steps.yml:27:9:28:6 | Run Step |
1919
| .github/workflows/poisonable_steps.yml:28:9:29:6 | Run Step |
20-
| .github/workflows/poisonable_steps.yml:29:9:29:43 | Run Step |
20+
| .github/workflows/poisonable_steps.yml:29:9:30:6 | Run Step |
21+
| .github/workflows/poisonable_steps.yml:30:9:31:6 | Run Step |
22+
| .github/workflows/poisonable_steps.yml:31:9:32:6 | Run Step |
23+
| .github/workflows/poisonable_steps.yml:32:9:33:6 | Run Step |
24+
| .github/workflows/poisonable_steps.yml:33:9:34:6 | Run Step |
25+
| .github/workflows/poisonable_steps.yml:34:9:35:6 | Run Step |
26+
| .github/workflows/poisonable_steps.yml:35:9:36:6 | Run Step |
27+
| .github/workflows/poisonable_steps.yml:37:9:38:6 | Run Step |
28+
| .github/workflows/poisonable_steps.yml:38:9:39:6 | Run Step |
29+
| .github/workflows/poisonable_steps.yml:39:9:40:6 | Run Step |
30+
| .github/workflows/poisonable_steps.yml:40:9:40:74 | Run Step |

0 commit comments

Comments
 (0)