mirror of
https://github.com/alibaba/open-code-review.git
synced 2026-08-25 08:32:59 +00:00
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.
This commit is contained in:
parent
83dacc2725
commit
72bfe7a872
3 changed files with 63 additions and 21 deletions
|
|
@ -120,24 +120,37 @@ semantic convention like `feat(auth): add OAuth2 support`):
|
|||
|
||||
```yaml
|
||||
- name: Run OCR review
|
||||
env:
|
||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||
BASE_REF: ${{ github.base_ref }}
|
||||
HEAD_REF: ${{ github.head_ref }}
|
||||
run: |
|
||||
ocr review \
|
||||
--background "${{ github.event.pull_request.title }}" \
|
||||
--from "origin/${{ github.base_ref }}" \
|
||||
--to "origin/${{ github.head_ref }}" \
|
||||
--background "$PR_TITLE" \
|
||||
--from "origin/$BASE_REF" \
|
||||
--to "origin/$HEAD_REF" \
|
||||
--format json --audience agent
|
||||
```
|
||||
|
||||
Pass PR-controlled values through `env:` rather than
|
||||
interpolating `${{ }}` directly into `run:`. GitHub substitutes
|
||||
`${{ }}` textually *before* the shell parses the line, so a PR
|
||||
title or branch name containing shell metacharacters would
|
||||
execute on your runner.
|
||||
|
||||
#### Custom rules
|
||||
|
||||
Pass a project-specific rule file with `--rule`:
|
||||
|
||||
```yaml
|
||||
- name: Run OCR review
|
||||
env:
|
||||
BASE_REF: ${{ github.base_ref }}
|
||||
HEAD_REF: ${{ github.head_ref }}
|
||||
run: |
|
||||
ocr review --rule ./my-rules.json \
|
||||
--from "origin/${{ github.base_ref }}" \
|
||||
--to "origin/${{ github.head_ref }}"
|
||||
--from "origin/$BASE_REF" \
|
||||
--to "origin/$HEAD_REF"
|
||||
```
|
||||
|
||||
See [Review Rules](../../review-rules/) for the schema.
|
||||
|
|
@ -149,10 +162,13 @@ to stay under your LLM provider's rate limits:
|
|||
|
||||
```yaml
|
||||
- name: Run OCR review
|
||||
env:
|
||||
BASE_REF: ${{ github.base_ref }}
|
||||
HEAD_REF: ${{ github.head_ref }}
|
||||
run: |
|
||||
ocr review --concurrency 5 \
|
||||
--from "origin/${{ github.base_ref }}" \
|
||||
--to "origin/${{ github.head_ref }}"
|
||||
--from "origin/$BASE_REF" \
|
||||
--to "origin/$HEAD_REF"
|
||||
```
|
||||
|
||||
#### Trigger pattern
|
||||
|
|
|
|||
|
|
@ -83,24 +83,33 @@ curl -o .github/workflows/ocr-review.yml \
|
|||
|
||||
```yaml
|
||||
- name: Run OCR review
|
||||
env:
|
||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||
BASE_REF: ${{ github.base_ref }}
|
||||
HEAD_REF: ${{ github.head_ref }}
|
||||
run: |
|
||||
ocr review \
|
||||
--background "${{ github.event.pull_request.title }}" \
|
||||
--from "origin/${{ github.base_ref }}" \
|
||||
--to "origin/${{ github.head_ref }}" \
|
||||
--background "$PR_TITLE" \
|
||||
--from "origin/$BASE_REF" \
|
||||
--to "origin/$HEAD_REF" \
|
||||
--format json --audience agent
|
||||
```
|
||||
|
||||
PR で制御可能な値は `${{ }}` を `run:` に直接展開するのではなく、`env:` 経由で渡してください。GitHub は `${{ }}` を shell が行を解析する *前に* テキストとして置換するため、shell のメタ文字を含む PR タイトルやブランチ名が runner 上で実行されてしまいます。
|
||||
|
||||
#### カスタムルール
|
||||
|
||||
`--rule` でプロジェクト固有のルールファイルを渡します。
|
||||
|
||||
```yaml
|
||||
- name: Run OCR review
|
||||
env:
|
||||
BASE_REF: ${{ github.base_ref }}
|
||||
HEAD_REF: ${{ github.head_ref }}
|
||||
run: |
|
||||
ocr review --rule ./my-rules.json \
|
||||
--from "origin/${{ github.base_ref }}" \
|
||||
--to "origin/${{ github.head_ref }}"
|
||||
--from "origin/$BASE_REF" \
|
||||
--to "origin/$HEAD_REF"
|
||||
```
|
||||
|
||||
スキーマは[レビュールール](../../review-rules/)を参照してください。
|
||||
|
|
@ -111,10 +120,13 @@ curl -o .github/workflows/ocr-review.yml \
|
|||
|
||||
```yaml
|
||||
- name: Run OCR review
|
||||
env:
|
||||
BASE_REF: ${{ github.base_ref }}
|
||||
HEAD_REF: ${{ github.head_ref }}
|
||||
run: |
|
||||
ocr review --concurrency 5 \
|
||||
--from "origin/${{ github.base_ref }}" \
|
||||
--to "origin/${{ github.head_ref }}"
|
||||
--from "origin/$BASE_REF" \
|
||||
--to "origin/$HEAD_REF"
|
||||
```
|
||||
|
||||
#### トリガーモード
|
||||
|
|
|
|||
|
|
@ -101,24 +101,35 @@ curl -o .github/workflows/ocr-review.yml \
|
|||
|
||||
```yaml
|
||||
- name: Run OCR review
|
||||
env:
|
||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||
BASE_REF: ${{ github.base_ref }}
|
||||
HEAD_REF: ${{ github.head_ref }}
|
||||
run: |
|
||||
ocr review \
|
||||
--background "${{ github.event.pull_request.title }}" \
|
||||
--from "origin/${{ github.base_ref }}" \
|
||||
--to "origin/${{ github.head_ref }}" \
|
||||
--background "$PR_TITLE" \
|
||||
--from "origin/$BASE_REF" \
|
||||
--to "origin/$HEAD_REF" \
|
||||
--format json --audience agent
|
||||
```
|
||||
|
||||
把 PR 可控的值通过 `env:` 传入,不要把 `${{ }}` 直接插值进 `run:`。GitHub 在
|
||||
shell 解析该行 *之前* 就已把 `${{ }}` 做了文本替换,因此包含 shell 元字符的 PR
|
||||
标题或分支名会在你的 runner 上被执行。
|
||||
|
||||
#### 自定义规则
|
||||
|
||||
用 `--rule` 传入项目专属规则文件:
|
||||
|
||||
```yaml
|
||||
- name: Run OCR review
|
||||
env:
|
||||
BASE_REF: ${{ github.base_ref }}
|
||||
HEAD_REF: ${{ github.head_ref }}
|
||||
run: |
|
||||
ocr review --rule ./my-rules.json \
|
||||
--from "origin/${{ github.base_ref }}" \
|
||||
--to "origin/${{ github.head_ref }}"
|
||||
--from "origin/$BASE_REF" \
|
||||
--to "origin/$HEAD_REF"
|
||||
```
|
||||
|
||||
schema 见[评审规则](../../review-rules/)。
|
||||
|
|
@ -129,10 +140,13 @@ schema 见[评审规则](../../review-rules/)。
|
|||
|
||||
```yaml
|
||||
- name: Run OCR review
|
||||
env:
|
||||
BASE_REF: ${{ github.base_ref }}
|
||||
HEAD_REF: ${{ github.head_ref }}
|
||||
run: |
|
||||
ocr review --concurrency 5 \
|
||||
--from "origin/${{ github.base_ref }}" \
|
||||
--to "origin/${{ github.head_ref }}"
|
||||
--from "origin/$BASE_REF" \
|
||||
--to "origin/$HEAD_REF"
|
||||
```
|
||||
|
||||
#### 触发模式
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue