-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathenvpath-injection-medium.yaml
More file actions
87 lines (78 loc) · 2.42 KB
/
Copy pathenvpath-injection-medium.yaml
File metadata and controls
87 lines (78 loc) · 2.42 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: PATH Injection Medium - Normal Triggers
on:
# Normal triggers with limited permissions
pull_request:
types: [opened, synchronize]
push:
branches: [main]
schedule:
- cron: '0 0 * * *'
jobs:
# MEDIUM: Untrusted input written to GITHUB_PATH with normal trigger
unsafe-pr:
runs-on: ubuntu-latest
steps:
- name: Set PATH from PR body
run: |
echo "${{ github.event.pull_request.body }}" >> "$GITHUB_PATH"
- name: Use the PATH
run: 'echo "PATH updated"'
# MEDIUM: Untrusted input from PR title
unsafe-pr-title:
runs-on: ubuntu-latest
steps:
- name: Set PATH from PR title
run: |
echo "${{ github.event.pull_request.title }}" >> $GITHUB_PATH
# MEDIUM: Untrusted input from head ref
unsafe-head-ref:
runs-on: ubuntu-latest
steps:
- name: Set PATH from head ref
run: |
echo "${{ github.event.pull_request.head.ref }}" >> "$GITHUB_PATH"
# MEDIUM: Multiple untrusted inputs
unsafe-multiple:
runs-on: ubuntu-latest
steps:
- name: Set multiple paths
run: |
echo "${{ github.event.pull_request.title }}" >> $GITHUB_PATH
echo "${{ github.event.pull_request.user.login }}" >> $GITHUB_PATH
# SAFE: Using realpath to validate the path
safe-with-realpath:
runs-on: ubuntu-latest
steps:
- name: Set PATH safely with realpath
env:
USER_PATH: ${{ github.event.pull_request.body }}
run: |
VALIDATED_PATH=$(realpath "$USER_PATH")
echo "$VALIDATED_PATH" >> "$GITHUB_PATH"
# SAFE: Using environment variable as intermediary with validation
safe-with-env-validation:
runs-on: ubuntu-latest
steps:
- name: Set PATH with validation
env:
USER_PATH: ${{ github.event.pull_request.body }}
run: |
# Validate the path exists and is a directory
if [ -d "$USER_PATH" ]; then
echo "$USER_PATH" >> "$GITHUB_PATH"
fi
# SAFE: Not using untrusted input
safe-trusted-only:
runs-on: ubuntu-latest
steps:
- name: Set PATH from trusted sources
run: |
echo "${{ github.sha }}" >> "$GITHUB_PATH"
echo "${{ github.workspace }}/bin" >> "$GITHUB_PATH"
# SAFE: Using hardcoded paths
safe-hardcoded:
runs-on: ubuntu-latest
steps:
- name: Set known PATH
run: |
echo "/opt/tools/bin" >> "$GITHUB_PATH"