Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

GitHub Actions: Security

Back


Security

Secret Management


Token Management


Preventing Script Injection


Authentication - OpenID Connect



Lab: Script Injection - PR

name: 20 security

on:
  pull_request:

jobs:
  unsafe-pr:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Check the PR title
        run: |
          title=$
          if [[ $title =~ ^feat ]]; then
            echo "PR is a feature"
            exit 0
          else
            echo "PR is not a feature"
            exit 1
          fi
  safe-pr:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Check the PR title
        env:
          TITLE: $
        run: |
          if [[ $TITLE =~ ^feat ]]; then
            echo "PR is a feature"
            exit 0
          else
            echo "PR is not a feature"
            exit 1
          fi

pic

PR title is passed as an environment variable, not inserted directly into the Bash script.

pic

script injection: title=”feature: new readme”; ls -R if [[$title =~ ^feat]]; then