Skip to content

Commit

Permalink
add semgrep for github workflows (aptos-labs#9522)
Browse files Browse the repository at this point in the history
add semgrep for GitHub workflows
  • Loading branch information
gedigi authored and Aalok Thakkar committed Aug 13, 2023
1 parent f3da0f1 commit 31b5aab
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/linters/semgrep/pull-request-target-code-checkout.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
rules:
- id: pull-request-target-code-checkout
languages:
- yaml
message: This GitHub Actions workflow file uses `pull_request_target` and checks
out code from the incoming pull request. When using `pull_request_target`,
the Action runs in the context of the target repository, which includes
access to all repository secrets. Please ensure you have `permission-check`
enabled for the jobs that check out code. Please see
https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
for additional mitigations.
metadata:
category: security
owasp:
- A01:2021 - Broken Access Control
cwe:
- "CWE-913: Improper Control of Dynamically-Managed Code Resources"
references:
- https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
- https://github.com/justinsteven/advisories/blob/master/2021_github_actions_checkspelling_token_leak_via_advice_symlink.md
technology:
- github-actions
subcategory:
- audit
likelihood: MEDIUM
impact: LOW
confidence: MEDIUM
license: Commons Clause License Condition v1.0[LGPL-2.1-only]
vulnerability_class:
- Code Injection
patterns:
- pattern-either:
- pattern-inside: |
on:
...
pull_request_target: ...
...
...
- pattern-inside: |
on: [..., pull_request_target, ...]
...
- pattern-inside: |
on: pull_request_target
...
- pattern-inside: |
jobs:
...
$JOBNAME:
...
- pattern-not-inside: |
needs: [permission-check]
...
- pattern: |
...
uses: "$ACTION"
- metavariable-regex:
metavariable: $ACTION
regex: actions/checkout@.*
severity: WARNING
24 changes: 24 additions & 0 deletions .github/workflows/semgrep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Semgrep

on:
workflow_dispatch:
pull_request:
types: [labeled, opened, synchronize, reopened, auto_merge_enabled]

jobs:
semgrep:
name: semgrep/ci
runs-on: ubuntu-latest

container:
image: returntocorp/semgrep

# Skip any PR created by dependabot to avoid permission issues:
if: (github.actor != 'dependabot[bot]')

steps:
- uses: actions/checkout@v3
- run: semgrep ci
env:
SEMGREP_RULES: >-
./.github/linters/semgrep/pull-request-target-code-checkout.yaml

0 comments on commit 31b5aab

Please sign in to comment.