Class: Rules::UnscopedAppToken

Inherits:
Base
  • Object
show all
Defined in:
lib/rules/unscoped_app_token.rb

Instance Method Summary collapse

Instance Method Details

#check(workflow) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rules/unscoped_app_token.rb', line 7

def check(workflow)
  findings = []

  workflow.jobs.each do |_job_id, job|
    workflow.steps(job).each do |step|
      next unless step["uses"]&.include?("create-github-app-token")

      with = step["with"] || {}
      has_permissions = with.keys.any? { |k| k.start_with?("permission-") }

      unless has_permissions
        line = workflow.line_of(/create-github-app-token/)
        findings << finding(workflow,
          line: line || 0,
          message: "App token inherits blanket installation permissions",
          fix: "Add permission-<name>: write inputs to scope the token"
        )
      end
    end
  end

  findings
end

#descriptionObject



4
# File 'lib/rules/unscoped_app_token.rb', line 4

def description = "GitHub App token without scoped permissions"

#nameObject



3
# File 'lib/rules/unscoped_app_token.rb', line 3

def name = "unscoped-app-token"

#severityObject



5
# File 'lib/rules/unscoped_app_token.rb', line 5

def severity = :high