Class: Rules::ShellInjectionExpr

Inherits:
Base
  • Object
show all
Includes:
GuardPatterns
Defined in:
lib/rules/shell_injection_expr.rb

Constant Summary collapse

PATTERN =
/\$\{\{\s*(#{DANGEROUS_CONTEXTS.map { |c| Regexp.escape(c) }.join('|')})/

Constants included from GuardPatterns

GuardPatterns::DANGEROUS_CONTEXTS, GuardPatterns::JOB_PROPERTIES, GuardPatterns::SAFE_TRIGGERS

Instance Method Summary collapse

Methods included from GuardPatterns

#guarded_by_safe_event?, #safe_trigger_only?, #strip_inline_comment

Instance Method Details

#check(workflow) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rules/shell_injection_expr.rb', line 13

def check(workflow)
    findings = []

    return [] if safe_trigger_only?(workflow)

    workflow.lines_of(PATTERN).each do |line_num|
        line = workflow.line_content(line_num)
        next if line.strip.start_with?('#')
        next unless in_run_block?(workflow, line_num)
        next if guarded_by_safe_event?(workflow, line_num)

        match = line.match(PATTERN)
        next unless match

        findings << finding(workflow,
            line: line_num,
            code: workflow.line_content(line_num).strip,
            message: "Attacker-controllable expression ${{ #{match[1]} }} in run: block — shell injection risk",
            fix: "Move to env: block and reference as $ENV_VAR in the shell"
        )
    end
    findings
end

#descriptionObject



8
# File 'lib/rules/shell_injection_expr.rb', line 8

def description = "Attacker-controllable ${{ }} expression in run: block"

#nameObject



7
# File 'lib/rules/shell_injection_expr.rb', line 7

def name = "shell-injection-expr"

#severityObject



9
# File 'lib/rules/shell_injection_expr.rb', line 9

def severity = :critical