Skip to content

Commit

Permalink
feat: add detection for injection in options parameter for services
Browse files Browse the repository at this point in the history
  • Loading branch information
hugo-syn committed Dec 24, 2024
1 parent b61ad7b commit 92bfbdb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions core/rules/rule_expression_injection.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ func (rule *RuleExpressionInjection) VisitWorkflowPre(n *actionlint.Workflow) er
return nil
}

// VisitJobPre is callback when visiting Job node before visiting its children.
func (rule *RuleExpressionInjection) VisitJobPre(n *actionlint.Job) error {

if n.Services != nil {
for _, s := range n.Services.Value {
rule.checkContainer(s.Container, "jobs.<job_id>.services", "<service_id>")
}
}

return nil
}

// VisitStep is callback when visiting Step node.
func (rule *RuleExpressionInjection) VisitStep(n *actionlint.Step) error {

Expand Down Expand Up @@ -294,3 +306,16 @@ func cleanLogMessages(errs []*actionlint.Error) {
e.Message = "Expression injection, " + msg[0] + "."
}
}

func (rule *RuleExpressionInjection) checkContainer(c *actionlint.Container, workflowKey, childWorkflowKeyPrefix string) {
if c == nil {
return
}
childWorkflowKey := workflowKey
if childWorkflowKeyPrefix != "" {
childWorkflowKey += "." + childWorkflowKeyPrefix
}
rule.checkString(c.Image, workflowKey)
//rule.checkEnv(c.Env, workflowKey+".env.<env_id>") // e.g. jobs.<job_id>.container.env.<env_id>
rule.checkString(c.Options, workflowKey)
}

0 comments on commit 92bfbdb

Please sign in to comment.