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
|
# File 'lib/rules/shell_injection_jq.rb', line 14
def check(workflow)
findings = []
workflow.raw_lines.each_with_index do |line, i|
line_num = i + 1
if line.match?(JQ_PATTERN)
var_match = line.match(/\$\{(\w+)\}/)
next unless var_match
var_name = var_match[1]
next unless potentially_attacker_controlled?(var_name)
findings << finding(workflow,
line: line_num,
code: line.strip,
message: "${#{var_name}} interpolated in double-quoted jq argument — $(command) executes via bash substitution",
fix: "Use jq --arg: jq -nc --arg #{var_name.downcase} \"$#{var_name}\" '{text: $#{var_name.downcase}}'"
)
end
if line.match?(CURL_JSON_PATTERN)
var_match = line.match(/\$\{(\w+)\}/)
next unless var_match
var_name = var_match[1]
next unless potentially_attacker_controlled?(var_name)
findings << finding(workflow,
line: line_num,
code: line.strip,
message: "${#{var_name}} interpolated in double-quoted curl JSON — command substitution risk",
fix: "Build JSON payload with jq -nc --arg instead of string interpolation"
)
end
end
findings
end
|