Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 34 additions & 36 deletions .github/workflows/python-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
name: CI
# .github/workflows/ci-vulnerable.yml
name: CI (VULNERABLE EXAMPLE)

on:
pull_request:
workflow_dispatch:

permissions: # added using https://github.com/step-security/secure-repo
contents: read
id-token: write
pull_request_target:
types: [opened, reopened, synchronize]

jobs:
build:
# Runs with the base repository's context on PRs, including from forks
runs-on: ubuntu-latest

# Overly broad permissions allow write actions against the repo
permissions:
contents: write # dangerous on pull_request_target
pull-requests: write # also risky

env:
# Secrets are available in this context and will be reachable by attacker-controlled code
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Harden Runner
uses: step-security/harden-runner@446798f8213ac2e75931c1b0769676d927801858 # v2.10.0
with:
policy: Test-policy

- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Set up Python 3.11
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version: 3.11

- name: Install dependencies
run: |
pip install -r requirements.txt

- name: Echo
run: echo "213" > README.md

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v35

- name: List all changed files
run: |
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo "$file was changed"
done
- name: Checkout PR code (DANGEROUS)
uses: actions/checkout@v4
with:
# Explicitly pulls the contributor's fork and branch (attacker-controlled)
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
# Leaves write-capable credentials in the repo working copy
persist-credentials: true

- name: Install deps
run: npm ci

- name: Build
run: npm run build

- name: Publish artifact (runs with write token)
run: |
echo "Pretend we publish or tag a release here"
# Attacker-controlled code above can already run with write and secrets