Class: Rules::GithubScriptInjection
Constant Summary
collapse
- DANGEROUS_EXPR_PATTERN =
/\$\{\{\s*(#{DANGEROUS_CONTEXTS.map { |c| Regexp.escape(c) }.join('|')})/
- INPUT_EXPR_PATTERN =
/\$\{\{\s*((?:inputs|github\.event\.inputs)\.[^\s}]+)/
Rules::GuardPatterns::DANGEROUS_CONTEXTS, Rules::GuardPatterns::JOB_PROPERTIES, Rules::GuardPatterns::SAFE_TRIGGERS
Instance Method Summary
collapse
#guarded_by_safe_event?, #safe_trigger_only?, #strip_inline_comment
Instance Method Details
#check(workflow) ⇒ Object
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
|
# File 'lib/rules/github_script_injection.rb', line 14
def check(workflow)
findings = []
safe_triggers = safe_trigger_only?(workflow)
workflow.raw_lines.each_with_index do |line, idx|
line_num = idx + 1
next if line.strip.start_with?('#')
next unless in_github_script_block?(workflow, line_num)
has_dangerous = line.match?(DANGEROUS_EXPR_PATTERN)
has_input = line.match?(INPUT_EXPR_PATTERN)
next unless has_dangerous || has_input
guarded = guarded_by_safe_event?(workflow, line_num)
if has_input
match = line.match(INPUT_EXPR_PATTERN)
if match
findings << finding(workflow,
line: line_num,
code: line.strip,
message: "Attacker-controllable expression \${{ #{match[1]} }} in actions/github-script — JavaScript injection risk",
fix: "Pass input via env: block and reference as process.env.VAR"
)
end
end
if has_dangerous && !safe_triggers && !guarded
match = line.match(DANGEROUS_EXPR_PATTERN)
if match
findings << finding(workflow,
line: line_num,
code: line.strip,
message: "Attacker-controllable expression \${{ #{match[1]} }} in actions/github-script — JavaScript injection risk",
fix: "Use context.payload instead: context.payload.pull_request.title"
)
end
end
end
findings
end
|
#description ⇒ Object
8
|
# File 'lib/rules/github_script_injection.rb', line 8
def description = "Attacker-controllable ${{ }} expression in actions/github-script"
|
#name ⇒ Object
7
|
# File 'lib/rules/github_script_injection.rb', line 7
def name = "github-script-injection"
|
#severity ⇒ Object
9
|
# File 'lib/rules/github_script_injection.rb', line 9
def severity = :critical
|