Ccodemod

codemod/azure-pipelines-task-param-injection

Scan Azure Pipelines YAML pipelines for task and script invocations that interpolate untrusted parameters or variables into command/task inputs in ways that can enable parameter or command injection, and report precise findings with security-oriented remediation guidance and metrics.

azure-pipelinessecurityyamlmininganalysis
Public
0 executions

Run locally

npx codemod @codemod/azure-pipelines-task-param-injection

@codemod/azure-pipelines-task-param-injection

Read-only mining codemod for Azure Pipelines YAML that detects task and script surfaces where dynamic pipeline expressions are interpolated into shell-executed command strings or forwarded argument fields.

What It Detects

  • Top-level script-bearing steps such as script, bash, pwsh, and powershell
  • Task inputs such as script, inlineScript, Inline, InlineScript, arguments, ScriptArguments, command, commandOptions, options, arg, args, and targetArguments
  • Template expressions ${{ ... }}, macros $(...), runtime expressions $[ ... ], and simple locally derived variables that later flow into sensitive sinks
  • Risk context for inline script bodies, argument strings, command-option fields, and derived-variable cases

What It Excludes

  • Non-executable metadata such as displayName, condition, dependsOn, pool settings, and similar declarative fields
  • Literal-only values with no dynamic expressions
  • Standalone env: mappings that are not consumed in the same command sink
  • Parameter declarations or variable declarations by themselves unless a sensitive sink consumes the derived value
  • Direct allowlisted parameter usage when the parameter declaration has explicit values: enumeration and the expression is used as a standalone token

Reporting

This codemod does not rewrite source files.

For each finding it emits structured runtime warnings with:

  • file, line, column, yamlPath, and stepIndex
  • taskType, taskRef, field, and sinkClass
  • expressionKind, sourceKind, and risk
  • Evidence and remediation guidance for parameter and command injection risks, including CWE-20 and CWE-78 mappings

It also emits these metrics via codemod:metrics:

  • azurepipelines_parameter_injection.finding
  • azurepipelines_parameter_injection.files_with_findings
  • azurepipelines_parameter_injection.by_task_type
  • azurepipelines_parameter_injection.by_field
  • azurepipelines_parameter_injection.by_expression_kind
  • azurepipelines_parameter_injection.by_risk
  • azurepipelines_parameter_injection.by_source_kind
  • azurepipelines_parameter_injection.inline_vs_argument
  • azurepipelines_parameter_injection.allowlist_excluded

Target Files

  • azure-pipelines.yml
  • azure-pipelines.yaml
  • .azure-pipelines/**/*.yml
  • .azure-pipelines/**/*.yaml
  • pipelines/**/*.yml
  • pipelines/**/*.yaml
  • .ado/**/*.yml
  • .ado/**/*.yaml

Usage

bash

Remediation Guidance

  • Avoid concatenating user-controlled parameters or variables into inline shell bodies.
  • Prefer task-native structured inputs instead of raw argument strings.
  • Map parameters through explicit allowlists before use.
  • Pass arguments as separate validated values where the Azure task supports that shape.
  • Use fixed command templates instead of forwarding untrusted extra-args strings.

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.