Skip to content

Security: pin GitHub Actions to SHA hashes#257

Open
jorgebraz wants to merge 1 commit intomasterfrom
security/pin-actions-to-sha
Open

Security: pin GitHub Actions to SHA hashes#257
jorgebraz wants to merge 1 commit intomasterfrom
security/pin-actions-to-sha

Conversation

@jorgebraz
Copy link

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.

@codacy-production
Copy link

codacy-production bot commented Mar 24, 2026

Not up to standards ⛔

🔴 Issues 1 critical

Alerts:

⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
Security 1 critical

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. Give us feedback

Copy link

@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

This PR is currently not up to standards due to a combination of incomplete implementation and significant security risks. While the objective is to pin actions to SHA hashes, the 'ahmadnassri/action-dependabot-auto-merge@v2' action was overlooked. Furthermore, multiple files (comment_issue.yml, create_issue.yml, create_issue_on_label.yml) use SHA hashes for actions/github-script v3.0.0 while labeling them as v2.0.0, which may introduce breaking changes. Most critically, .github/workflows/auto-merge.yml contains a high-risk security vulnerability involving pull_request_target and an unsafe checkout of untrusted code, which should be addressed alongside the SHA pinning.

About this PR

  • The action 'ahmadnassri/action-dependabot-auto-merge@v2' in '.github/workflows/auto-merge.yml' was not updated to a SHA hash. This omission leaves the workflow vulnerable to supply chain attacks, which contradicts the stated security goal of this PR.
  • Across several files, the SHA hashes used for 'actions/github-script' correspond to version v3.0.0, but the accompanying comments refer to v2.0.0. This inconsistency should be resolved by either using the v2.0.0 SHA or updating the version labels to v3.0.0 after verifying compatibility.

Test suggestions

  • Ensure all actions in .github/workflows/auto-merge.yml are pinned to immutable SHAs.
  • Ensure all actions in .github/workflows/comment_issue.yml are pinned to immutable SHAs.
  • Ensure all actions in .github/workflows/create_issue.yml are pinned to immutable SHAs.
  • Ensure all actions in .github/workflows/create_issue_on_label.yml are pinned to immutable SHAs.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Ensure all actions in .github/workflows/auto-merge.yml are pinned to immutable SHAs.

🗒️ Improve review quality by adding custom instructions

Comment on lines +11 to 13
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2
with:
ref: ${{ github.event.pull_request.head.sha }}

Choose a reason for hiding this comment

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

🔴 HIGH RISK

This workflow uses pull_request_target and checks out the pull request's head code via ref: ${{ github.event.pull_request.head.sha }}. This allows potentially untrusted code from the pull request to run with access to repository secrets. Even with the check for dependabot[bot], this pattern is discouraged. For dependabot auto-merging, consider using the pull_request event or avoiding the checkout of the head ref in a privileged context.

Try running the following prompt in your IDE agent:

In .github/workflows/auto-merge.yml, evaluate if the pull_request_target trigger can be replaced with pull_request and if the ref parameter for actions/checkout can be removed to ensure the workflow runs in a restricted context.

- name: Add comment after sync
if: github.event.label.name == env.JIRA_ISSUE_LABEL
uses: actions/github-script@v2.0.0
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # v2.0.0

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

The SHA hash corresponds to v3.0.0 but is labeled as v2.0.0. Use the correct hash for v2.0.0 to maintain consistency.

Suggested change
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # v2.0.0
uses: actions/github-script@70edcca421867c870248c82302824b2167104b90 # v2.0.0

- name: Change Title
if: github.event.label.name == env.JIRA_ISSUE_LABEL
uses: actions/github-script@v2.0.0
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # v2.0.0

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

The SHA hash corresponds to v3.0.0 but is labeled as v2.0.0. Use the correct hash for v2.0.0 to maintain consistency.

Suggested change
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # v2.0.0
uses: actions/github-script@70edcca421867c870248c82302824b2167104b90 # v2.0.0

- name: Add comment after sync
if: env.JIRA_CREATE_ISSUE_AUTO == 'true'
uses: actions/github-script@v2.0.0
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # v2.0.0

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

The SHA hash corresponds to v3.0.0 but is labeled as v2.0.0. Use the correct hash for v2.0.0 to maintain consistency.

Suggested change
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # v2.0.0
uses: actions/github-script@70edcca421867c870248c82302824b2167104b90 # v2.0.0

- name: Update GitHub issue
if: env.JIRA_CREATE_ISSUE_AUTO == 'true'
uses: actions/github-script@v2.0.0
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # v2.0.0

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

The SHA hash corresponds to v3.0.0 but is labeled as v2.0.0. Use the correct hash for v2.0.0 to maintain consistency.

Suggested change
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # v2.0.0
uses: actions/github-script@70edcca421867c870248c82302824b2167104b90 # v2.0.0

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

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

The SHA hash corresponds to v3.0.0 but is labeled as v2.0.0. Use the correct hash for v2.0.0 to maintain consistency.

Suggested change
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # v2.0.0
uses: actions/github-script@70edcca421867c870248c82302824b2167104b90 # v2.0.0

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

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

The SHA hash corresponds to v3.0.0 but is labeled as v2.0.0. Use the correct hash for v2.0.0 to maintain consistency.

Suggested change
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # v2.0.0
uses: actions/github-script@70edcca421867c870248c82302824b2167104b90 # v2.0.0

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

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

The SHA hash 6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 corresponds to v3.0.0, which contradicts the v2.0.0 label. Use the correct SHA for v2.0.0 to maintain consistency.

Suggested change
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # v2.0.0
uses: actions/github-script@70edcca421867c870248c82302824b2167104b90 # v2.0.0

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

Actions left as tags: 0
@jorgebraz jorgebraz force-pushed the security/pin-actions-to-sha branch from 6275fd7 to 63844dd Compare March 24, 2026 18:05
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.

1 participant