-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcache-poisoning-write.yaml
More file actions
72 lines (68 loc) · 2.67 KB
/
Copy pathcache-poisoning-write.yaml
File metadata and controls
72 lines (68 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Cache Directory Write Vulnerability Example
# Demonstrates direct writes into package-manager cache directories from
# `run:` scripts. The CachePoisoningRule reports each write at one of two
# severities:
#
# - "(suspicious)" — the job has no cache action, so the write only persists
# for the duration of this run. Defense-in-depth surfaces the pattern
# without overstating the severity.
# - "(critical)" — the job has a cache action (`actions/cache`,
# `actions/cache/save`, `actions/cache/restore`, or `actions/setup-*` with
# `cache:` enabled). The cache action will persist whatever sits under the
# cache path at job end, so the write is treated as a real persistence
# vector for later workflow runs.
name: Cache Directory Write Vulnerability
on:
push:
branches: [main]
pull_request:
jobs:
# CRITICAL: write to ~/.npm followed by actions/cache/save.
npm-write-then-save:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Plant payload into npm cache
run: |
# VULNERABLE: writes attacker-controlled bytes under ~/.npm before
# the save step persists the directory for later runs.
mkdir -p ~/.npm/_cacache/content-v2/sha512
echo "payload" >> ~/.npm/_cacache/content-v2/sha512/malicious
- uses: actions/cache/save@v4
with:
path: ~/.npm
key: npm-${{ github.sha }}
# CRITICAL: setup-node with cache: npm counts as a cache action; any write
# under ~/.npm earlier in the job will be persisted.
setup-node-cache-with-prior-write:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Mutate npm cache
run: cp ./payload ~/.npm/_cacache/content-v2/sha512/payload
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
# CRITICAL: yarn cache directory write before actions/cache.
yarn-write-then-cache:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Plant into yarn cache
run: tar -xf payload.tar -C ~/.yarn/cache
- uses: actions/cache@v4
with:
path: ~/.yarn/cache
key: yarn-${{ github.sha }}
# SUSPICIOUS: writes into a cache directory but no cache action persists it.
# The rule still surfaces the pattern as defense-in-depth — the directory
# may be saved by a downstream workflow that reads from this job's outputs.
suspicious-write-only:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Mutate gradle cache without persistence
run: |
# SUSPICIOUS: written but not saved by this job.
touch ~/.gradle/caches/modules-2/files-2.1/payload