Skip to content

Security: pin GitHub Actions to SHA hashes#77

Open
jorgebraz wants to merge 27 commits intomasterfrom
security/pin-actions-to-sha
Open

Security: pin GitHub Actions to SHA hashes#77
jorgebraz wants to merge 27 commits intomasterfrom
security/pin-actions-to-sha

Conversation

@jorgebraz
Copy link
Copy Markdown

Pins all GitHub Actions from mutable tags/branches to immutable SHA hashes.

This prevents supply chain attacks like the TeamPCP/Trivy incident (March 2026), where attackers force-pushed tags to point at malicious commits.

Auto-generated by the Codacy security audit script.

Replaces mutable tag/branch references with immutable SHA hashes
to prevent supply chain attacks (ref: TeamPCP/Trivy March 2026).

Actions left as tags: 0
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Mar 24, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

Copy link
Copy Markdown

@codacy-production codacy-production Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Although this PR successfully addresses the security goal of pinning GitHub Actions to immutable SHAs, it contains critical logic flaws and security risks in the modified workflows—particularly in .github/workflows/comment_issue.yml. Multiple steps rely on environment variables in if conditions that are not available in the job context, which will cause these steps to be skipped. Additionally, the use of expression interpolation in github-script poses a script injection risk. These issues must be resolved before merging to ensure the workflows remain functional.

About this PR

  • The PR lacks evidence (such as workflow run logs) confirming that the specific commit SHAs used are verified and functional. Additionally, the description contains a reference to 'March 2026', which appears to be a typo that should be corrected for accuracy.

Test suggestions

  • Verify that the 'Comment issue on Jira' workflow still executes correctly with pinned SHAs for github-script, gajira-login, and gajira-comment.
  • Verify that the 'Create issue on Jira' workflow still executes correctly with pinned SHAs for gajira-login, gajira-create, and github-script.
  • Verify that the 'Create issue on Jira when labeled' workflow still executes correctly with pinned SHAs for gajira-login, gajira-create, and github-script.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify that the 'Comment issue on Jira' workflow still executes correctly with pinned SHAs for github-script, gajira-login, and gajira-comment.
2. Verify that the 'Create issue on Jira' workflow still executes correctly with pinned SHAs for gajira-login, gajira-create, and github-script.
3. Verify that the 'Create issue on Jira when labeled' workflow still executes correctly with pinned SHAs for gajira-login, gajira-create, and github-script.

🗒️ Improve review quality by adding custom instructions

if: env.JIRA_CREATE_COMMENT_AUTO == 'true' && env.GITHUB_ISSUE_TYPE == 'issue' && env.GITHUB_ISSUE_HAS_JIRA_ISSUE_LABEL == 'true'
id: login
uses: atlassian/gajira-login@v2.0.0
uses: atlassian/gajira-login@90a599561baaf8c05b080645ed73db7391c246ed # v2.0.0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 HIGH RISK

The if conditions on line 59 (and similarly at lines 50, 57, 68, and 83) rely on environment variables like env.GITHUB_ISSUE_TYPE which are not available to the job-level if context. These variables are step-local and evaluated after the if condition. This will cause the steps to be skipped.

Update the conditions to use step outputs instead:

In .github/workflows/comment_issue.yml, update the if conditions for all steps to use step outputs (e.g., steps.github_issue_type.outputs.result) instead of env variables.

if: env.JIRA_CREATE_COMMENT_AUTO == 'true'
id: github_issue_type
uses: actions/github-script@v2.0.0
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # v2.0.0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM RISK

The script blocks at lines 26 and 42 use ${{ toJson(...) }} to interpolate GitHub event data directly into JavaScript. This is a security anti-pattern and a potential script injection vector.

Refactor the steps to pass github.event.issue data as environment variables, then access them via process.env within the script block.

if: env.JIRA_CREATE_COMMENT_AUTO == 'true' && env.GITHUB_ISSUE_TYPE == 'issue' && env.GITHUB_ISSUE_HAS_JIRA_ISSUE_LABEL == 'true'
id: extract_jira_number
uses: actions/github-script@v2.0.0
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # v2.0.0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM RISK

Suggestion: The script at lines 77-79 will throw a TypeError if the issue title does not match the expected Jira project regex, as it attempts to access index [1] of a null result. Update the 'Extract Jira number' script to safely handle cases where the regex match fails.

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.

3 participants