Skip to content

Feature: detect secrets exposed beyond the steps that need them #1816

@Danil42Russia

Description

@Danil42Russia

Pre-submission checks

  • I am not reporting a bug (crash, false positive/negative, etc). These must be filed via the bug report template.
  • I have looked through both the open and closed issues for a duplicate request.

What's the problem this feature will solve?

In GitHub Actions, environment variables can now be declared at the workflow level, at the individual job level, and at the step level.

If variables are declared for all steps, values in env that depend on secrets.* become accessible to a wider range of steps than might be necessary :(

jobs:
  example:
    runs-on: ubuntu-latest

    env:
      JOB_SECRET: ${{ secrets.JOB_SECRET }} # bad: available to all `steps`

    steps:
      - name: vulnerable step
        shell: bash
        run: |
          # could steal secrets 
          ./vulnerable_script.sh

      - name: working step
        shell: bash
        run: |
          ./working_script.sh

      - name: vulnerable step
        shell: bash
        run: |
          # could steal secrets
          ./vulnerable_script.sh

Describe the solution you'd like

  1. warn if workflow.env uses a value from secrets.*
  2. warn if jobs.<job_id>.env uses a value from secrets.*
  3. do not warn if jobs.<job_id>.steps[*].env uses a value from secrets.*

Additional context

name: CI

on:
  push:
  workflow_dispatch:

env:
  WORKFLOW_SECRET: ${{ secrets.WORKFLOW_SECRET }} # bad: available to all `jobs` and `steps`

jobs:
  test:
    runs-on: ubuntu-latest

    env:
      JOB_SECRET: ${{ secrets.JOB_SECRET }} # bad: available to all `steps`

    steps:
      - name: step 1
        shell: bash
        run: |
          echo $WORKFLOW_SECRET | base64 | base64
          echo $JOB_SECRET | base64 | base64
          echo $STEP_SECRET | base64 | base64

      - name: step 2
        env:
          STEP_SECRET: ${{ secrets.STEP_SECRET }} # good: available to this `step`
        shell: bash
        run: |
          echo $WORKFLOW_SECRET | base64 | base64
          echo $JOB_SECRET | base64 | base64
          echo $STEP_SECRET | base64 | base64

      - name: step 3
        shell: bash
        run: |
          echo $WORKFLOW_SECRET | base64 | base64
          echo $JOB_SECRET | base64 | base64
          echo $STEP_SECRET | base64 | base64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions