Skip to content

gh aw compile generates CodeQL code-injection alert for ${{ runner.tool_cache }} in shell run block #57775

Description

@kkruel8100

Summary

gh aw compile generates lock workflows that interpolate ${{ runner.tool_cache }} directly inside an executable shell run: block.

CodeQL flags this as actions/code-injection/medium.

We have several workflows that use on.workflow-call and use a centralized repo ops pattern. The centralized workflow is extremely important to use to maintain workflows in one place.

The ${{ runner.tool_cache }} appears more broadly but the CodeQL alerts appear related to workflows that use the on.workflow-call.

Generated Code

- name: Set runtime paths
  id: set-runtime-paths
  run:  |
    if [ -z "${RUNNER_TOOL_CACHE:-}" ]; then
      echo "RUNNER_TOOL_CACHE=${{ runner.tool_cache }}" >> "$GITHUB_ENV"
    fi

CodeQL Alert

Potential code injection in ${{ runner.tool_cache }}, which may be controlled by external user.

Observed Context

This appears in generated .lock.yml files produced by gh aw compile.
The source .md workflow files do not contain this shell line. It is introduced by compilation, so manual editing is not durable.

Version

Observed in v 0.87.10

Proposed fix

Replace with

  env:
    GH_AW_RUNNER_TOOL_CACHE: ${{ runner.tool_cache }}
  run:  |
    if [ -z "${RUNNER_TOOL_CACHE:-}" ]; then
      echo "RUNNER_TOOL_CACHE=${{ GH_AW_RUNNER_TOOL_CACHE }}" >> "$GITHUB_ENV"
    fi

Request

Please update gh aw compile so ${{ runner.tool_cache }} is passed through env: and referenced as a shell variable, rather then being interpolated directly into executable run: script text.

Impact

We have a centralized workflow with a large number of reusable workflows, so the count of CodeQL alerts is significant.

Thank you for reviewing the matter.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions