-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrules.go
More file actions
1061 lines (921 loc) · 33.1 KB
/
Copy pathrules.go
File metadata and controls
1061 lines (921 loc) · 33.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (C) 2023-2026 Eric Cornelissen
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package ades
import (
"fmt"
"regexp"
"strings"
"github.com/ericcornelissen/go-gha-models"
"golang.org/x/mod/semver"
)
type rule struct {
appliesTo func(step *gha.Step) bool
extractFrom func(step *gha.Step) string
fix func(violation *Violation) []fix
id string
title string
description string
}
type fix struct {
// New is the replacement string to fix a violation.
New string
// Old is a regular expression to search and replace with in order to fix a violation.
Old regexp.Regexp
}
var actionRule8398a7ActionSlack = rule{
appliesTo: func(step *gha.Step) bool {
return hasName(step, "8398a7/action-slack")
},
id: "ADES107",
title: "Expression in 'custom_payload' input of '8398a7/action-slack'",
description: `
When an expression appears in the 'custom_payload' input of '8398a7/action-slack' you can avoid any
potential attack by extracting the expression into an environment variable and using the environment
variable instead.
For example, given the workflow snippet:
- name: Example step
uses: 8398a7/action-slack@v3
with:
custom_payload: |
{ attachments: [{ color: '${{ inputs.color }}' }] }
it can be made safer by converting it into:
- name: Example step
uses: 8398a7/action-slack@v3
env:
COLOR: ${{ inputs.color }} # <- Assign the expression to an environment variable
with:
custom_payload: |
{ attachments: [{ color: process.env.COLOR }] }
# ^^^^^^^^^^^^^^^^^
# | Replace the expression with the environment variable
`,
extractFrom: func(step *gha.Step) string {
return step.With["custom_payload"]
},
}
var actionRuleActionsGitHubScript = rule{
appliesTo: func(step *gha.Step) bool {
return hasName(step, "actions/github-script")
},
id: "ADES101",
title: "Expression in 'actions/github-script' script",
description: `
When an expression appears in a 'actions/github-script' script you can avoid potential attacks by
extracting the expression into an environment variable and using the environment variable instead.
For example, given the workflow snippet:
- name: Example step
uses: actions/github-script@v6
with:
script: console.log('Hello ${{ inputs.name }}')
it can be made safer by converting it into:
- name: Example step
uses: actions/github-script@v6
env:
NAME: ${{ inputs.name }} # <- Assign the expression to an environment variable
with:
script: console.log(` + "`" + `Hello ${process.env.NAME}` + "`" + `)
# ^ ^^^^^^^^^^^^^^^^^^^
# | | Replace the expression with the environment variable
# |
# | Note: the use of backticks is required in this example (for interpolation)
`,
extractFrom: func(step *gha.Step) string {
return step.With["script"]
},
}
var actionRuleAddnabDockerRunAction = rule{
appliesTo: func(step *gha.Step) bool {
return hasName(step, "addnab/docker-run-action")
},
id: "ADES105",
title: "Expression in 'run' input of 'addnab/docker-run-action'",
description: `
When an expression appears in the 'run' input of 'addnab/docker-run-action' you can avoid any
potential attack by removing the expression. There is no safe way to use untrusted inputs here
without risking injection.
Do NOT pass environment variables into the container through the action's options input. This opens
up alternative attack vectors because the options are not validated.
`,
extractFrom: func(step *gha.Step) string {
return step.With["run"]
},
}
var actionRuleAmadevusPwshScript = rule{
appliesTo: func(step *gha.Step) bool {
return hasName(step, "Amadevus/pwsh-script")
},
id: "ADES110",
title: "Expression in 'script' input of 'Amadevus/pwsh-script'",
description: `
When an expression appears in the 'script' input of 'Amadevus/pwsh-script' you can avoid any
potential attack by extracting the expression into an environment variable and using the environment
variable instead.
For example, given the workflow snippet:
- name: Example step
uses: Amadevus/pwsh-script@v2
with:
script: |
Write-Output 'Hello ${{ inputs.name }}'
it can be made safer by converting it into:
- name: Example step
uses: Amadevus/pwsh-script@v2
env:
NAME: ${{ inputs.name }} # <- Assign the expression to an environment variable
with:
script: |
Write-Output "Hello $env:NAME"
# ^ ^^^^^^^^^
# | | Replace the expression with the environment variable
# |
# | Note: the use of double quotes is required in this example (for interpolation)
`,
extractFrom: func(step *gha.Step) string {
return step.With["script"]
},
}
var actionRuleAnthropicsClaudeCodeAction = rule{
appliesTo: func(step *gha.Step) bool {
if !hasName(step, "anthropics/claude-code-action") {
return false
}
return step.With["allowed_non_write_users"] != ""
},
id: "ADES300",
title: "Expression in 'prompt' input of 'anthropics/claude-code-action'",
description: `
When an expression appears in the 'prompt' input of 'anthropics/claude-code-action' it allows for
prompt injection. If the 'allowed_non_write_users' option is used this enables untrusted users to
escalate their privileges through Claude Code. To avoid attacks, remove the expression from the
prompt or disable the 'allowed_non_write_users' option.
For example, given the workflow snippet:
- name: Example step
uses: anthropics/claude-code-action@v1
with:
allowed_non_write_users: '*'
prompt: |
Summarize the issue title ${{ github.event.issue.title }}
it can be made safer by converting it into:
- name: Example step
uses: anthropics/claude-code-action@v1
with:
# DO NOT use 'allowed_non_write_users'
prompt: |
Summarize the issue title ${{ github.event.issue.title }}
`,
extractFrom: func(step *gha.Step) string {
return step.With["prompt"]
},
}
var actionRuleAppleboySshAction = rule{
appliesTo: func(step *gha.Step) bool {
return hasName(step, "appleboy/ssh-action")
},
id: "ADES108",
title: "Expression in 'script' input of 'appleboy/ssh-action'",
description: `
When an expression appears in the 'script' input of 'appleboy/ssh-action' you can avoid any
potential attack by extracting the expression into an environment variable and using the environment
variable instead.
For example, given the workflow snippet:
- name: Example step
uses: appleboy/ssh-action@v1
with:
script: echo 'Hello ${{ inputs.name }}'
it can be made safer by converting it into:
- name: Example step
uses: appleboy/ssh-action@v1
env:
NAME: ${{ inputs.name }} # <- Assign the expression to an environment variable
with:
envs: NAME # <- Pass the environment variable through SSH
script: echo "Hello $NAME"
# ^ ^^^^^
# | | Replace the expression with the environment variable
# |
# | Note: the use of double quotes is required in this example (for interpolation)
`,
extractFrom: func(step *gha.Step) string {
return step.With["script"]
},
}
var actionRuleAquasecurityTrivyAction = rule{
appliesTo: func(step *gha.Step) bool {
if !hasName(step, "aquasecurity/trivy-action") {
return false
}
return isAtOrAfterVersion(step, "v0.31.0") && isBeforeVersion(step, "v0.34.0")
},
id: "ADES207",
title: "Expression in any input of 'aquasecurity/trivy-action'",
description: `
When an expression is used in _any_ input of 'aquasecurity/trivy-action' starting from v0.31.0 up
to v0.33.1 it may be used to execute arbitrary shell commands, see GHSA-9p44-j4g5-cfx5. To mitigate
this, upgrade the action to a non-vulnerable version.
`,
extractFrom: func(step *gha.Step) string {
var sb strings.Builder
for _, v := range step.With {
sb.WriteString(v)
}
return sb.String()
},
}
var actionRuleAtlassianGajiraCreate = rule{
appliesTo: func(step *gha.Step) bool {
if !hasName(step, "atlassian/gajira-create") {
return false
}
return isBeforeVersion(step, "v2.0.1")
},
id: "ADES202",
title: "Expression in 'summary' input of 'atlassian/gajira-create'",
description: `
When an expression is used in the 'summary' input of 'atlassian/gajira-create' in v2.0.0 or earlier
it may be used to execute arbitrary JavaScript code, see GHSA-4xqx-pqpj-9fqw. To mitigate this,
upgrade the action to a non-vulnerable version.
`,
extractFrom: func(step *gha.Step) string {
return step.With["summary"]
},
}
var actionRuleAzureCli = rule{
appliesTo: func(step *gha.Step) bool {
return hasName(step, "azure/cli")
},
id: "ADES115",
title: "Expression in 'inlineScript' input of 'azure/cli'",
description: `
When an expression appears in the 'inlineScript' input of 'azure/cli' you can avoid any potential
attack by extracting the expression into an environment variable and using the environment variable
instead.
For example, given the workflow snippet:
- name: Example step
uses: azure/cli@v2.2.0
with:
inlineScript: |
az vm create --name '${{ inputs.name }}'
it can be made safer by converting it into:
- name: Example step
uses: azure/cli@v2.2.0
env:
NAME: ${{ inputs.name }} # <- Assign the expression to an environment variable
with:
item_exec: |
az vm create --name "$NAME"
# / ^^^^^
# | | Replace the expression with the environment variable
# |
# | Note: the use of double quotes is required in this example (for interpolation)
`,
extractFrom: func(step *gha.Step) string {
return step.With["inlineScript"]
},
}
var actionRuleAzurePowershell = rule{
appliesTo: func(step *gha.Step) bool {
return hasName(step, "azure/powershell")
},
id: "ADES113",
title: "Expression in 'inlineScript' input of 'azure/powershell'",
description: `
When an expression appears in the 'inlineScript' input of 'azure/powershell' you can avoid any
potential attack by extracting the expression into an environment variable and using the environment
variable instead.
For example, given the workflow snippet:
- name: Example step
uses: azure/powershell@v2.0.0
with:
azPSVersion: latest
inlineScript: |
Write-Output 'Hello ${{ inputs.name }}'
it can be made safer by converting it into:
- name: Example step
uses: azure/powershell@v2.0.0
env:
NAME: ${{ inputs.name }} # <- Assign the expression to an environment variable
with:
azPSVersion: latest
inlineScript: |
Write-Output "Hello $env:NAME"
# ^ ^^^^^^^^^
# | | Replace the expression with the environment variable
# |
# | Note: the use of double quotes is required in this example (for interpolation)
`,
extractFrom: func(step *gha.Step) string {
return step.With["inlineScript"]
},
}
var actionRuleCardinalbyJsEvalAction = rule{
appliesTo: func(step *gha.Step) bool {
return hasName(step, "cardinalby/js-eval-action")
},
id: "ADES106",
title: "Expression in 'expression' input of 'cardinalby/js-eval-action'",
description: `
When an expression appears in the 'expression' input of 'cardinalby/js-eval-action' you can avoid
any potential attack by extracting the expression into an environment variable and using the
environment variable instead.
For example, given the workflow snippet:
- name: Example step
uses: cardinalby/js-eval-action@v1
with:
expression: 1 + parseInt(${{ inputs.value }})
it can be made safer by converting it into:
- name: Example step
uses: cardinalby/js-eval-action@v1
env:
VALUE: ${{ inputs.value }} # <- Assign the expression to an environment variable
with:
expression: 1 + parseInt(env.VALUE)
# ^^^^^^^^^
# | Replace the expression with the environment variable
`,
extractFrom: func(step *gha.Step) string {
return step.With["expression"]
},
fix: func(violation *Violation) []fix {
var step gha.Step
switch source := (violation.source).(type) {
case *gha.Manifest:
step = source.Runs.Steps[violation.stepIndex]
case *gha.Workflow:
step = source.Jobs[violation.jobKey].Steps[violation.stepIndex]
}
name := getVariableNameForExpression(violation.Problem)
if _, ok := step.Env[name]; ok {
return nil
}
fixes := fixAddEnvVar(step, name, violation.Problem)
fixes = append(fixes, fixReplaceIn(
step.With["expression"],
violation.Problem,
"env."+name,
))
return fixes
},
}
var actionRuleDevorbitusYqActionOutput = rule{
appliesTo: func(step *gha.Step) bool {
return hasName(step, "devorbitus/yq-action-output")
},
id: "ADES112",
title: "Expression in 'cmd' input of 'devorbitus/yq-action-output'",
description: `
When an expression appears in the 'cmd' input of 'devorbitus/yq-action-output' you can avoid any
potential attack by extracting the expression into an environment variable and using the environment
variable instead.
For example, given the workflow snippet:
- name: Example step
uses: devorbitus/yq-action-output@v1.1
with:
cmd: yq eval '${{ inputs.query }}' 'config.yml'
it can be made safer by converting it into:
- name: Example step
uses: devorbitus/yq-action-output@v1.1
env:
QUERY: ${{ inputs.query }} # <- Assign the expression to an environment variable
with:
cmd: yq eval "$QUERY" 'config.yml'
# / ^^^^^^
# | | Replace the expression with the environment variable
# |
# | Note: the use of double quotes is required in this example (for interpolation)
`,
extractFrom: func(step *gha.Step) string {
return step.With["cmd"]
},
}
var actionRuleEriccornelissenGitTagAnnotationAction = rule{
appliesTo: func(step *gha.Step) bool {
if !hasName(step, "ericcornelissen/git-tag-annotation-action") {
return false
}
return isBeforeVersion(step, "v1.0.1")
},
id: "ADES200",
title: "Expression in 'tag' input of 'ericcornelissen/git-tag-annotation-action'",
description: `
When an expression is used in the 'tag' input of 'ericcornelissen/git-tag-annotation-action' in
v1.0.0 or earlier it may be used to execute arbitrary shell commands, see GHSA-hgx2-4pp9-357g. To
mitigate this, upgrade the action to a non-vulnerable version.
`,
extractFrom: func(step *gha.Step) string {
return step.With["tag"]
},
}
var actionRuleFishShopSyntaxCheck = rule{
appliesTo: func(step *gha.Step) bool {
if !hasName(step, "fish-shop/syntax-check") {
return false
}
return isBeforeVersion(step, "v1.6.12")
},
id: "ADES206",
title: "Expression in 'pattern' input of 'fish-shop/syntax-check'",
description: `
When an expression is used in the 'pattern' input of 'fish-shop/syntax-check' in v1.6.11 or earlier
it may be used to execute arbitrary shell commands, see GHSA-xj87-mqvh-88w2. To mitigate this,
upgrade the action to a non-vulnerable version.
`,
extractFrom: func(step *gha.Step) string {
return step.With["pattern"]
},
}
var actionRuleGautamkrishnarBlogPostWorkflow = rule{
appliesTo: func(step *gha.Step) bool {
return hasName(step, "gautamkrishnar/blog-post-workflow")
},
id: "ADES114",
title: "Expression in 'item_exec' input of 'gautamkrishnar/blog-post-workflow'",
description: `
When an expression appears in the 'item_exec' input of 'gautamkrishnar/blog-post-workflow' you can
avoid any potential attack by extracting the expression into an environment variable and using the
environment variable instead.
For example, given the workflow snippet:
- name: Example step
uses: gautamkrishnar/blog-post-workflow@1.9.4
with:
item_exec: |
post.includes('${{ inputs.substr }}')
it can be made safer by converting it into:
- name: Example step
uses: gautamkrishnar/blog-post-workflow@1.9.4
env:
SUBSTR: ${{ inputs.substr }} # <- Assign the expression to an environment variable
with:
item_exec: |
post.includes(` + "`" + `${process.env.SUBSTR}` + "`" + `)
# / ^ ^^^^^^^^^^^^^^^^^^
# | | | Replace the expression with the environment variable
# | |
# | | Note: the use of ${...} is required in this example (for interpolating)
# |
# | Note: the use of backticks is required in this example (for interpolation)
`,
extractFrom: func(step *gha.Step) string {
return step.With["item_exec"]
},
}
var actionRuleJannekemRunPythonScriptAction = rule{
appliesTo: func(step *gha.Step) bool {
return hasName(step, "jannekem/run-python-script-action")
},
id: "ADES109",
title: "Expression in 'script' input of 'jannekem/run-python-script-action'",
description: `
When an expression appears in the 'script' input of 'jannekem/run-python-script-action' you can
avoid any potential attack by extracting the expression into an environment variable and using the
environment variable instead.
For example, given the workflow snippet:
- name: Example step
uses: jannekem/run-python-script-action@v1
with:
script: print("Hello ${{ inputs.name }}")
it can be made safer by converting it into:
- name: Example step
uses: jannekem/run-python-script-action@v1
env:
NAME: ${{ inputs.name }} # <- Assign the expression to an environment variable
with:
script: print(f"Hello {os.getenv('NAME')}")
# ^ ^^^^^^^^^^^^^^^^^^^
# | | Replace the expression with the environment variable
# |
# | Note: the use of string interpolation is required in this example
`,
extractFrom: func(step *gha.Step) string {
return step.With["script"]
},
}
var actionRuleKcebGitMessageAction = rule{
appliesTo: func(step *gha.Step) bool {
if !hasName(step, "kceb/git-message-action") {
return false
}
return isBeforeVersion(step, "v1.2.0")
},
id: "ADES201",
title: "Expression in 'sha' input of 'kceb/git-message-action'",
description: `
When an expression is used in the 'sha' input of 'kceb/git-message-action' in v1.1.0 or earlier it
may be used to execute arbitrary shell commands (no vulnerability identifier available). To mitigate
this, upgrade the action to a non-vulnerable version.
`,
extractFrom: func(step *gha.Step) string {
return step.With["sha"]
},
}
var actionRuleLycheeverseLycheeAction = rule{
appliesTo: func(step *gha.Step) bool {
if !hasName(step, "lycheeverse/lychee") {
return false
}
return isBeforeVersion(step, "v2.0.2")
},
id: "ADES204",
title: "Expression in 'lycheeVersion' input of 'lycheeverse/lychee'",
description: `
When an expression is used in the 'lycheeVersion' input of 'lycheeverse/lychee' in v2.0.1 or earlier
it may be used to execute arbitrary shell commands, see GHSA-65rg-554r-9j5x. To mitigate this,
upgrade the action to a non-vulnerable version.
`,
extractFrom: func(step *gha.Step) string {
return step.With["lycheeVersion"]
},
}
var actionRuleMikefarahYq = rule{
appliesTo: func(step *gha.Step) bool {
return hasName(step, "mikefarah/yq")
},
id: "ADES111",
title: "Expression in 'cmd' input of 'mikefarah/yq'",
description: `
When an expression appears in the 'cmd' input of 'mikefarah/yq' you can avoid any potential attack
by extracting the expression into an environment variable and using the environment variable
instead.
For example, given the workflow snippet:
- name: Example step
uses: mikefarah/yq@master
with:
cmd: yq '${{ inputs.query }}' 'config.yml'
it can be made safer by converting it into:
- name: Example step
uses: mikefarah/yq@master
env:
QUERY: ${{ inputs.query }} # <- Assign the expression to an environment variable
with:
cmd: yq "$QUERY" 'config.yml'
# / ^^^^^^
# | | Replace the expression with the environment variable
# |
# | Note: the use of double quotes is required in this example (for interpolation)
`,
extractFrom: func(step *gha.Step) string {
return step.With["cmd"]
},
}
var actionRuleOziProjectPublish = rule{
appliesTo: func(step *gha.Step) bool {
if !hasName(step, "OZI-Project/publish") {
return false
}
return isAtOrAfterVersion(step, "v1.13.2") && isBeforeVersion(step, "v1.13.6")
},
id: "ADES205",
title: "Expression in 'pull-request-body' input of 'OZI-Project/publish'",
description: `
When an expression is used in the 'pull-request-body' input of 'OZI-Project/publish' between v1.13.2
and v1.13.5 it may be used to execute arbitrary shell commands, see GHSA-2487-9f55-2vg9. To mitigate
this, upgrade the action to a non-vulnerable version.
`,
extractFrom: func(step *gha.Step) string {
return step.With["pull-request-body"]
},
}
var actionRuleRootsIssueCloserActionIssueCloseMessage = rule{
appliesTo: func(step *gha.Step) bool {
return hasName(step, "roots/issue-closer") || hasName(step, "roots/issue-closer-action")
},
id: "ADES102",
title: "Expression in 'issue-close-message' input of 'roots/issue-closer-action'",
description: `
When an expression appears in the 'issue-close-message' input of 'roots/issue-closer-action' it is
interpreted as an ES6-style template literal. You can avoid potential attacks by extracting the
expression into an environment variable and using the environment variable instead.
For example, given the workflow snippet:
- name: Example step
uses: roots/issue-closer-action@v1
with:
issue-close-message: Closing ${{ github.event.issue.title }}
it can be made safer by converting it into:
- name: Example step
uses: roots/issue-closer-action@v1
env:
NAME: ${{ github.event.issue.title }} # <- Assign the expression to an environment variable
with:
issue-close-message: Closing ${process.env.NAME}
# ^^^^^^^^^^^^^^^^^^^
# | Replace the expression with the environment variable
`,
extractFrom: func(step *gha.Step) string {
return step.With["issue-close-message"]
},
fix: func(violation *Violation) []fix {
var step gha.Step
switch source := (violation.source).(type) {
case *gha.Manifest:
step = source.Runs.Steps[violation.stepIndex]
case *gha.Workflow:
step = source.Jobs[violation.jobKey].Steps[violation.stepIndex]
}
name := getVariableNameForExpression(violation.Problem)
if _, ok := step.Env[name]; ok {
return nil
}
fixes := fixAddEnvVar(step, name, violation.Problem)
fixes = append(fixes, fixReplaceIn(
step.With["issue-close-message"],
violation.Problem,
fmt.Sprintf("${process.env.%s}", name),
))
return fixes
},
}
var actionRuleRootsIssueCloserActionPrCloseMessage = rule{
appliesTo: func(step *gha.Step) bool {
return actionRuleRootsIssueCloserActionIssueCloseMessage.appliesTo(step)
},
id: "ADES103",
title: "Expression in 'pr-close-message' input of 'roots/issue-closer-action'",
description: `
When an expression appears in the 'pr-close-message' input of 'roots/issue-closer-action' it is
interpreted as an ES6-style template literal. You can avoid potential attacks by extracting the
expression into an environment variable and using the environment variable instead.
For example, given the workflow snippet:
- name: Example step
uses: roots/issue-closer-action@v1
with:
pr-close-message: Closing ${{ github.event.issue.title }}
it can be made safer by converting it into:
- name: Example step
uses: roots/issue-closer-action@v1
env:
NAME: ${{ github.event.issue.title }} # <- Assign the expression to an environment variable
with:
pr-close-message: Closing ${process.env.NAME}
# ^^^^^^^^^^^^^^^^^^^
# | Replace the expression with the environment variable
`,
extractFrom: func(step *gha.Step) string {
return step.With["pr-close-message"]
},
}
var actionRuleSergeysovaJqAction = rule{
appliesTo: func(step *gha.Step) bool {
return hasName(step, "sergeysova/jq-action")
},
id: "ADES104",
title: "Expression in 'cmd' input of 'sergeysova/jq-action'",
description: `
When an expression appears in the 'cmd' input of 'sergeysova/jq-action' you can avoid any potential
attack by extracting the expression into an environment variable and using the environment variable
instead.
For example, given the workflow snippet:
- name: Example step
uses: sergeysova/jq-action@v2
with:
cmd: jq .version ${{ github.event.inputs.file }} -r
it can be made safer by converting it into:
- name: Example step
uses: sergeysova/jq-action@v2
env:
FILE: ${{ github.event.inputs.file }} # <- Assign the expression to an environment variable
with:
cmd: jq .version "$FILE" -r
# / ^^^^^
# | | Replace the expression with the environment variable
# |
# | Note: use double quotes to avoid argument splitting
`,
extractFrom: func(step *gha.Step) string {
return step.With["cmd"]
},
}
var actionRuleSkitionekNotifyMicrosoftTeams = rule{
appliesTo: func(step *gha.Step) bool {
if !hasName(step, "Skitionek/notify-microsoft-teams") {
return false
}
return isBeforeVersion(step, "v1.0.9")
},
id: "ADES116",
title: "Expression in 'overwrite' input of 'Skitionek/notify-microsoft-teams'",
description: `
When an expression appears in the 'overwrite' input of 'Skitionek/notify-microsoft-teams' you can
avoid any potential attack by extracting the expression into an environment variable and using the
environment variable instead.
For example, given the workflow snippet:
- name: Example step
uses: Skitionek/notify-microsoft-teams@v1.0.8
with:
overwrite: |
{title: "${{ inputs.title }}"}
it can be made safer by converting it into:
- name: Example step
uses: Skitionek/notify-microsoft-teams@v1.0.8
env:
TITLE: ${{ inputs.title }} # <- Assign the expression to an environment variable
with:
overwrite: |
{title: ` + "`" + `${process.env.TITLE}` + "`" + `}
# ^ ^^^^^^^^^^^^^^^^^
# | | Replace the expression with the environment variable
# |
# | Note: the use of backticks is required for interpolation
`,
extractFrom: func(step *gha.Step) string {
return step.With["overwrite"]
},
}
var actionRuleSonarSourceSonarqubeScanAction = rule{
appliesTo: func(step *gha.Step) bool {
if !hasName(step, "SonarSource/sonarqube-scan-action") {
return false
}
return isAtOrAfterVersion(step, "v4.0.0") && isBeforeVersion(step, "v5.3.1")
},
id: "ADES203",
title: "Expression in 'args' input of 'SonarSource/sonarqube-scan-action'",
description: `
When an expression is used in the 'args' input of 'SonarSource/sonarqube-scan-action' between v4.0.0
and v5.3.0 it may be used to execute arbitrary shell commands, see GHSA-f79p-9c5r-xg88. To mitigate
this, upgrade the action to a non-vulnerable version.
`,
extractFrom: func(step *gha.Step) string {
return step.With["args"]
},
}
var stepRuleRun = rule{
appliesTo: func(step *gha.Step) bool {
return len(step.Run) > 0
},
id: "ADES100",
title: "Expression in 'run:' directive",
description: `
When an expression appears in a 'run:' directive you can avoid potential attacks by extracting the
expression into an environment variable and using the environment variable instead.
For example, given the workflow snippet:
- name: Example step
run: |
echo 'Hello ${{ inputs.name }}'
it can be made safer by converting it into:
- name: Example step
env:
NAME: ${{ inputs.name }} # <- Assign the expression to an environment variable
run: |
echo "Hello $NAME"
# ^ ^^^^^
# | | Replace the expression with the environment variable
# |
# | Note: the use of double quotes is required in this example (for interpolation)
Note that the changes depend on the runner and shell being used. For example, on Windows (or when
using 'shell: powershell') the environment variable must be accessed as '$Env:NAME'.
`,
extractFrom: func(step *gha.Step) string {
return step.Run
},
}
var rules = []rule{
actionRule8398a7ActionSlack,
actionRuleActionsGitHubScript,
actionRuleAddnabDockerRunAction,
actionRuleAmadevusPwshScript,
actionRuleAnthropicsClaudeCodeAction,
actionRuleAppleboySshAction,
actionRuleAquasecurityTrivyAction,
actionRuleAtlassianGajiraCreate,
actionRuleAzureCli,
actionRuleAzurePowershell,
actionRuleCardinalbyJsEvalAction,
actionRuleDevorbitusYqActionOutput,
actionRuleEriccornelissenGitTagAnnotationAction,
actionRuleFishShopSyntaxCheck,
actionRuleGautamkrishnarBlogPostWorkflow,
actionRuleJannekemRunPythonScriptAction,
actionRuleKcebGitMessageAction,
actionRuleLycheeverseLycheeAction,
actionRuleMikefarahYq,
actionRuleOziProjectPublish,
actionRuleRootsIssueCloserActionIssueCloseMessage,
actionRuleRootsIssueCloserActionPrCloseMessage,
actionRuleSergeysovaJqAction,
actionRuleSkitionekNotifyMicrosoftTeams,
actionRuleSonarSourceSonarqubeScanAction,
stepRuleRun,
}
func getRef(step *gha.Step) (string, bool) {
if ref := step.Uses.Ref; semver.IsValid(ref) {
return ref, true
}
if ref := step.Uses.Ref; semver.IsValid("v" + ref) {
return "v" + ref, true
}
if ref := step.Uses.Annotation; semver.IsValid(ref) {
return ref, true
}
return "", false
}
func hasName(step *gha.Step, name string) bool {
return strings.EqualFold(step.Uses.Name, name)
}
func isAtOrAfterVersion(step *gha.Step, version string) bool {
ref, ok := getRef(step)
if !ok {
return false
}
switch {
case semver.Canonical(ref) == ref:
return semver.Compare(ref, version) >= 0
case semver.MajorMinor(ref) == ref:
return semver.Compare(ref, semver.MajorMinor(version)) >= 0
default:
return semver.Compare(ref, semver.Major(version)) >= 0
}
}
func isBeforeVersion(step *gha.Step, version string) bool {
ref, ok := getRef(step)
if !ok {
return false
}
switch {
case semver.Canonical(ref) == ref:
return semver.Compare(ref, version) < 0
case semver.MajorMinor(ref) == ref:
return semver.Compare(ref, semver.MajorMinor(version)) < 0
default:
return semver.Compare(ref, semver.Major(version)) < 0
}
}
// Explain returns an explanation for a rule.
func Explain(ruleId string) (string, error) {
r, err := findRule(ruleId)
if err != nil {
return "", err
}
explanation := fmt.Sprintf("%s - %s\n%s", r.id, r.title, r.description)
return explanation, nil
}
// Fix produces a set of fixes to address the violation if possible. If the return value is nil the
// violation cannot be fixed automatically.
func Fix(violation *Violation) ([]fix, error) {
ruleId := violation.RuleId
r, err := findRule(ruleId)
if err != nil {
return nil, err
}