Update README.md #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: TOCTOU Pattern | |
on: | |
pull_request_target: | |
types: [labeled] | |
permissions: {} # No permissions by default | |
jobs: | |
vulnerable-pattern: | |
# DO NOT USE THIS PATTERN - It is vulnerable to TOCTOU | |
if: github.event.label.name == 'approved' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pull-requests: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Wait for demo purposes | |
run: | | |
echo "Waiting 2 minutes to allow push of new commit..." | |
sleep 120 | |
# VULNERABLE: Could get different code than what was approved | |
- name: Checkout PR (Vulnerable) | |
run: | | |
gh pr checkout ${{ github.event.pull_request.number }} | |
# Show what we got | |
echo "Commit we got:" | |
git rev-parse HEAD | |
echo "Content of README.md:" | |
cat README.md | |
secure-pattern: | |
# USE THIS PATTERN - It is secure against TOCTOU | |
if: github.event.label.name == 'approved' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pull-requests: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Wait for demo purposes | |
run: | | |
echo "Waiting 2 minutes to allow push of new commit..." | |
sleep 120 | |
# SECURE: Gets exactly the code that was approved | |
- name: Checkout PR (Secure) | |
run: | | |
gh pr checkout ${{ github.event.pull_request.number }} --commit ${{ github.event.pull_request.head.sha }} | |
# Show what we got | |
echo "Commit we got:" | |
git rev-parse HEAD | |
echo "Content of README.md:" | |
cat README.md |