Skip to content

[BUG] v47: recommend mapfile for preventing unwanted code execution in CI? #2880

Description

@lkraav

Is there an existing issue for this?

  • I have searched the existing issues

Does this issue exist in the latest version?

  • I'm using the latest release

Describe the bug?

Potential README update? Issue might in the consumer shell step, not in tj-actions/changed-files itself, but I don't see any mapfile or similar use recommendation in README.

Claimed vulnerable usage pattern ⬇️

run: npx prettier --check ${{ steps.changed-files.outputs.all_changed_files }}

If a PR includes a file whose name itself looks like a CLI flag, GitHub expands that output directly into the shell command line.

Example:

  • attacker adds a file named --config=pwn.cjs
  • attacker also adds pwn.cjs

Generated shell command becomes:

npx prettier --check --config=pwn.cjs pwn.cjs

At that point Prettier does not see --config=pwn.cjs as a filename — it sees it as an option. Since Prettier can load JS config/plugin files, that can turn attacker-controlled repo content into code execution in CI.

Recommendation is to make boundaries explicit:

  • read the changed files as JSON
  • parse them into a bash array
  • invoke Prettier as: `npx prettier --check -- "${files[@]}"

Proposed solution template:

...
jobs:
  prettier:
    runs-on: ubuntu-slim
    steps:
      - uses: actions/checkout@v6
      - uses: ./.github/actions/restore-node-modules-cache
      - id: changed-files
        uses: tj-actions/changed-files@v47
        with:
          json: true
          escape_json: false
      - if: steps.changed-files.outputs.any_changed == 'true'
        env:
          CHANGED_FILES_JSON: ${{ steps.changed-files.outputs.all_changed_files }}
        run: |
          mapfile -t files < <(printf '%s' "$CHANGED_FILES_JSON" | jq -r '.[]')
          npx prettier --check -- "${files[@]}"

Is this a real problem? Should https://github.com/tj-actions/changed-files/blob/v47/README.md be upgraded?

To Reproduce

Follow https://github.com/tj-actions/changed-files/blob/v47/README.md as-is.

What OS are you seeing the problem on?

all

Expected behavior?

Perhaps README.md should harden its recommendations?

Relevant log output

N/A

Has all relevant logs been included?

  • I've included all relevant logs

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions