Skip to content

Commit 72bfe7a

Browse files
authored
docs(ci): pass untrusted PR fields via env to prevent script injection (#430)
The CI integration docs interpolated github.event.pull_request.title, github.base_ref and github.head_ref directly inside shell run: blocks. GitHub substitutes ${{ }} textually before the shell parses the line, so a PR title or branch name containing shell metacharacters executes on the runner of anyone who copies the snippet. Hoist all three into env: mappings and reference them as shell variables, matching action.yml:228-244 and the repo's own review rule at internal/config/rules/rule_docs/github_workflows.md:6. Applied identically to en, ja and zh; the three code blocks were byte-identical before and remain so.
1 parent 83dacc2 commit 72bfe7a

3 files changed

Lines changed: 63 additions & 21 deletions

File tree

  • pages/src/content/docs

pages/src/content/docs/en/integrations/ci.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,24 +120,37 @@ semantic convention like `feat(auth): add OAuth2 support`):
120120

121121
```yaml
122122
- name: Run OCR review
123+
env:
124+
PR_TITLE: ${{ github.event.pull_request.title }}
125+
BASE_REF: ${{ github.base_ref }}
126+
HEAD_REF: ${{ github.head_ref }}
123127
run: |
124128
ocr review \
125-
--background "${{ github.event.pull_request.title }}" \
126-
--from "origin/${{ github.base_ref }}" \
127-
--to "origin/${{ github.head_ref }}" \
129+
--background "$PR_TITLE" \
130+
--from "origin/$BASE_REF" \
131+
--to "origin/$HEAD_REF" \
128132
--format json --audience agent
129133
```
130134
135+
Pass PR-controlled values through `env:` rather than
136+
interpolating `${{ }}` directly into `run:`. GitHub substitutes
137+
`${{ }}` textually *before* the shell parses the line, so a PR
138+
title or branch name containing shell metacharacters would
139+
execute on your runner.
140+
131141
#### Custom rules
132142

133143
Pass a project-specific rule file with `--rule`:
134144

135145
```yaml
136146
- name: Run OCR review
147+
env:
148+
BASE_REF: ${{ github.base_ref }}
149+
HEAD_REF: ${{ github.head_ref }}
137150
run: |
138151
ocr review --rule ./my-rules.json \
139-
--from "origin/${{ github.base_ref }}" \
140-
--to "origin/${{ github.head_ref }}"
152+
--from "origin/$BASE_REF" \
153+
--to "origin/$HEAD_REF"
141154
```
142155

143156
See [Review Rules](../../review-rules/) for the schema.
@@ -149,10 +162,13 @@ to stay under your LLM provider's rate limits:
149162

150163
```yaml
151164
- name: Run OCR review
165+
env:
166+
BASE_REF: ${{ github.base_ref }}
167+
HEAD_REF: ${{ github.head_ref }}
152168
run: |
153169
ocr review --concurrency 5 \
154-
--from "origin/${{ github.base_ref }}" \
155-
--to "origin/${{ github.head_ref }}"
170+
--from "origin/$BASE_REF" \
171+
--to "origin/$HEAD_REF"
156172
```
157173

158174
#### Trigger pattern

pages/src/content/docs/ja/integrations/ci.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,33 @@ curl -o .github/workflows/ocr-review.yml \
8383

8484
```yaml
8585
- name: Run OCR review
86+
env:
87+
PR_TITLE: ${{ github.event.pull_request.title }}
88+
BASE_REF: ${{ github.base_ref }}
89+
HEAD_REF: ${{ github.head_ref }}
8690
run: |
8791
ocr review \
88-
--background "${{ github.event.pull_request.title }}" \
89-
--from "origin/${{ github.base_ref }}" \
90-
--to "origin/${{ github.head_ref }}" \
92+
--background "$PR_TITLE" \
93+
--from "origin/$BASE_REF" \
94+
--to "origin/$HEAD_REF" \
9195
--format json --audience agent
9296
```
9397
98+
PR で制御可能な値は `${{ }}` を `run:` に直接展開するのではなく、`env:` 経由で渡してください。GitHub は `${{ }}` を shell が行を解析する *前に* テキストとして置換するため、shell のメタ文字を含む PR タイトルやブランチ名が runner 上で実行されてしまいます。
99+
94100
#### カスタムルール
95101

96102
`--rule` でプロジェクト固有のルールファイルを渡します。
97103

98104
```yaml
99105
- name: Run OCR review
106+
env:
107+
BASE_REF: ${{ github.base_ref }}
108+
HEAD_REF: ${{ github.head_ref }}
100109
run: |
101110
ocr review --rule ./my-rules.json \
102-
--from "origin/${{ github.base_ref }}" \
103-
--to "origin/${{ github.head_ref }}"
111+
--from "origin/$BASE_REF" \
112+
--to "origin/$HEAD_REF"
104113
```
105114

106115
スキーマは[レビュールール](../../review-rules/)を参照してください。
@@ -111,10 +120,13 @@ curl -o .github/workflows/ocr-review.yml \
111120

112121
```yaml
113122
- name: Run OCR review
123+
env:
124+
BASE_REF: ${{ github.base_ref }}
125+
HEAD_REF: ${{ github.head_ref }}
114126
run: |
115127
ocr review --concurrency 5 \
116-
--from "origin/${{ github.base_ref }}" \
117-
--to "origin/${{ github.head_ref }}"
128+
--from "origin/$BASE_REF" \
129+
--to "origin/$HEAD_REF"
118130
```
119131

120132
#### トリガーモード

pages/src/content/docs/zh/integrations/ci.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,35 @@ curl -o .github/workflows/ocr-review.yml \
101101

102102
```yaml
103103
- name: Run OCR review
104+
env:
105+
PR_TITLE: ${{ github.event.pull_request.title }}
106+
BASE_REF: ${{ github.base_ref }}
107+
HEAD_REF: ${{ github.head_ref }}
104108
run: |
105109
ocr review \
106-
--background "${{ github.event.pull_request.title }}" \
107-
--from "origin/${{ github.base_ref }}" \
108-
--to "origin/${{ github.head_ref }}" \
110+
--background "$PR_TITLE" \
111+
--from "origin/$BASE_REF" \
112+
--to "origin/$HEAD_REF" \
109113
--format json --audience agent
110114
```
111115
116+
把 PR 可控的值通过 `env:` 传入,不要把 `${{ }}` 直接插值进 `run:`。GitHub 在
117+
shell 解析该行 *之前* 就已把 `${{ }}` 做了文本替换,因此包含 shell 元字符的 PR
118+
标题或分支名会在你的 runner 上被执行。
119+
112120
#### 自定义规则
113121

114122
用 `--rule` 传入项目专属规则文件:
115123

116124
```yaml
117125
- name: Run OCR review
126+
env:
127+
BASE_REF: ${{ github.base_ref }}
128+
HEAD_REF: ${{ github.head_ref }}
118129
run: |
119130
ocr review --rule ./my-rules.json \
120-
--from "origin/${{ github.base_ref }}" \
121-
--to "origin/${{ github.head_ref }}"
131+
--from "origin/$BASE_REF" \
132+
--to "origin/$HEAD_REF"
122133
```
123134

124135
schema 见[评审规则](../../review-rules/)。
@@ -129,10 +140,13 @@ schema 见[评审规则](../../review-rules/)。
129140

130141
```yaml
131142
- name: Run OCR review
143+
env:
144+
BASE_REF: ${{ github.base_ref }}
145+
HEAD_REF: ${{ github.head_ref }}
132146
run: |
133147
ocr review --concurrency 5 \
134-
--from "origin/${{ github.base_ref }}" \
135-
--to "origin/${{ github.head_ref }}"
148+
--from "origin/$BASE_REF" \
149+
--to "origin/$HEAD_REF"
136150
```
137151

138152
#### 触发模式

0 commit comments

Comments
 (0)