Skip to content

Add support for pinning tools to a checksum - #1098

Merged
shivammathur merged 1 commit into
shivammathur:developfrom
kmaeda-rakus:add-tool-checksum-verification
Jul 23, 2026
Merged

shivammathur merged 1 commit into
shivammathur:developfrom
kmaeda-rakus:add-tool-checksum-verification

Conversation

@kmaeda-rakus

Copy link
Copy Markdown
Contributor

Related discussion: None yet — happy to open one if the maintainers prefer.

Description

This PR adds opt-in checksum verification for the tools input to harden workflows against supply-chain attacks (e.g. a release artifact being replaced after a tag is moved, or a fallback download source being compromised).

A tool can now be pinned in a Docker-digest-like format:

- name: Setup PHP with tools pinned to a checksum
  uses: shivammathur/setup-php@v2
  with:
    php-version: '8.5'
    tools: composer:2.9.8@sha256:59b2c50e10cafa0d8efc19ede9a326d782f096c674a26baf98cf042ce23de890

Behaviour:

  • Supported for tools downloaded as phar archives, with sha256 and sha512.
  • The downloaded file is verified on Linux, macOS and Windows — including when it is served from the persistent tools cache — and the file and its cache entry are removed on mismatch with a ✗ log entry (fails the job under fail-fast, and always for composer, matching the existing failure semantics).
  • Specifying a checksum for tools set up as composer packages or via custom package scripts, or specifying a malformed hash, produces an explicit error instead of being silently ignored (fail-closed).

Implementation notes:

  • src/tools.ts parses and validates the @sha256:/@sha512: suffix and appends the checksum to the generated add_tool / Add-Tool invocation. The shell functions detect the checksum argument by its shaN: prefix, so existing argument positions and behaviour are unchanged.
  • verify_checksum in src/scripts/unix.sh uses sha256sum/sha512sum, shasum or openssl, whichever is available; Windows uses Get-FileHash.
  • The README example checksum is the actual sha256 of composer.phar 2.9.8 as published on getcomposer.org.

In case this PR introduced TypeScript/JavaScript code changes:

  • I have written test cases for the changes in this pull request
  • I have run npm run format before the commit.
  • I have run npm run lint before the commit.
  • I have run npm run release before the commit.
  • npm test returns with no unit test errors and all code covered.

In case this PR edits any scripts:

  • I have checked the edited scripts for syntax.
  • I have tested the changes in an integration test (If yes, provide workflow YAML and link).

🤖 Generated with Claude Code

Tools in the tools input can now be pinned to a checksum using the
tool:version@sha256:<hash> or tool:version@sha512:<hash> syntax.
The downloaded tool is verified against the checksum on all platforms,
including when it is served from the tools cache, and it is removed
along with its cache entry if the verification fails.

Checksum verification is supported for tools downloaded as phar
archives. Specifying a checksum for tools set up using composer
packages or custom package scripts results in an error.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b9ef680) to head (a1f0840).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@            Coverage Diff            @@
##           develop     #1098   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8         8           
  Lines          906       935   +29     
  Branches       318       328   +10     
=========================================
+ Hits           906       935   +29     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shivammathur
shivammathur merged commit 9a01b66 into shivammathur:develop Jul 23, 2026
70 checks passed
shivammathur pushed a commit that referenced this pull request Jul 23, 2026
Tools in the tools input can now be pinned to a checksum using the
tool:version@sha256:<hash> or tool:version@sha512:<hash> syntax.
The downloaded tool is verified against the checksum on all platforms,
including when it is served from the tools cache, and it is removed
along with its cache entry if the verification fails.

Checksum verification is supported for tools downloaded as phar
archives. Specifying a checksum for tools set up using composer
packages or custom package scripts results in an error.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>

This branch was previously deployed

1 inactive deployment
codecov — a1f08401 Deployed Jul 23, 2026 by kmaeda-rakus via Run (ubuntu-latest) #1082
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants