Automate GitHub Actions pinning to full-length commit SHAs for improved security - #26
Open
sonnyquinn24 with Copilot wants to merge 3 commits into
Open
Automate GitHub Actions pinning to full-length commit SHAs for improved security#26sonnyquinn24 with Copilot wants to merge 3 commits into
sonnyquinn24 with Copilot wants to merge 3 commits into
Conversation
…umentation Co-authored-by: sonnyquinn24 <227287527+sonnyquinn24@users.noreply.github.com>
Co-authored-by: sonnyquinn24 <227287527+sonnyquinn24@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Automate pinning of GitHub Actions to full-length commit SHAs
Automate GitHub Actions pinning to full-length commit SHAs for improved security
Sep 1, 2025
sonnyquinn24
marked this pull request as ready for review
September 1, 2025 09:16
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements comprehensive automation to pin GitHub Actions to full-length commit SHAs instead of version tags, significantly improving supply chain security by preventing potential malicious code injection through updated action versions.
What This PR Does
This PR adds a complete automation solution that:
.github/workflows/to identify unpinned GitHub Actions (e.g.,actions/checkout@v3)Security Impact
Before:
After:
This change prevents supply chain attacks where malicious actors could compromise action repositories and inject harmful code into new releases while maintaining the same version tag.
Implementation Details
Core Script:
scripts/pin-github-actions.js.ymland.yamlworkflow filesUsage Examples
Comprehensive Testing
Added
test/pin-github-actions.test.jswith 7 test cases covering:Documentation Updates
Updated README.md with:
Edge Cases Handled
✅ Already pinned actions - Skipped automatically
✅ Non-existent repositories - Graceful error handling
✅ Version tag resolution - Handles
v3,v3.8.1,main, etc.✅ YAML validation - Ensures workflows remain valid
✅ Multiple workflow files - Processes entire
.github/workflows/directoryReal-World Application
This automation successfully processed the existing
ci-cd.ymlworkflow, pinning 6 action references:actions/checkout@v3→actions/checkout@f43a0e5ff2bd294...actions/setup-node@v3→actions/setup-node@3235b876344d2a9a...Running the script again correctly detects that all actions are already pinned and makes no changes, demonstrating the idempotent behavior.
Dependencies Added
js-yaml@^4.1.0- For safe YAML parsing and serialization@octokit/rest@^20.0.2- For GitHub API integrationThis automation can be integrated into CI/CD pipelines to automatically maintain security best practices for GitHub Actions across all workflow files.
This pull request was created as a result of the following prompt from Copilot chat.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.