Skip to content

Commit 10660cb

Browse files
committed
ci(final-check): neutralise mentions and references before the bot posts
The check job runs the PR's code, which on a GitHub-hosted runner can rewrite anything later in that job, the report included. Until now only the check job cleaned that report. The comment job now cleans it too before TechEngineBot posts it: - every @ is dropped - #123, GH-123 and issue, PR and discussion links are broken - the body is capped at 65,000 characters So whatever a PR contains, the bot can't be made to mention anyone or cross-reference anything. The token text no longer says "for this repository only". One fine-grained TechEngineBot token now covers every GetTechAPI repo that has a final check. Refs #297
1 parent 0805569 commit 10660cb

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

‎.github/workflows/final-check.yml‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ name: final-check
77
# comment with the verdict; adding the label again edits that comment. This is
88
# the only place the TechEngineBot account is used.
99
#
10-
# The check job runs PR code, so it gets no secrets and a read-only token.
11-
# Only the comment job sees TECHENGINEBOT_TOKEN, which must be a fine-grained
12-
# token of TechEngineBot for this repository with Pull requests: read and write
13-
# and nothing else; the job refuses any other kind of token or account. Fork
14-
# PRs never get a comment.
10+
# The check job runs PR code, so it gets no secrets and a read-only token, and
11+
# the comment job doesn't trust its report. Only the comment job sees
12+
# TECHENGINEBOT_TOKEN, which must be a fine-grained token of TechEngineBot with
13+
# Pull requests: read and write and nothing else; the job refuses any other
14+
# kind of token or account. Fork PRs never get a comment.
1515
on:
1616
pull_request:
1717
types: [labeled]
@@ -190,7 +190,7 @@ jobs:
190190
fi
191191
case "$TOKEN" in
192192
github_pat_*) echo "ok=true" >> "$GITHUB_OUTPUT" ;;
193-
*) echo "::error::TECHENGINEBOT_TOKEN must be a fine-grained token (github_pat_...) of TechEngineBot, for this repository only, with Pull requests: read and write."
193+
*) echo "::error::TECHENGINEBOT_TOKEN must be a fine-grained token (github_pat_...) of TechEngineBot with Pull requests: read and write."
194194
exit 1 ;;
195195
esac
196196
@@ -203,7 +203,16 @@ jobs:
203203
github-token: ${{ secrets.TECHENGINEBOT_TOKEN }}
204204
script: |
205205
const marker = '<!-- techapi-final-check -->';
206-
const body = process.env.BODY || '';
206+
// The check job ran the PR's code, so its report is untrusted here:
207+
// drop every @ and break issue references and issue/PR links, so the
208+
// comment can neither mention anyone nor cross-reference anything.
209+
const zw = String.fromCharCode(0x200b); // zero-width space
210+
const body = (process.env.BODY || '')
211+
.replace(/@/g, '')
212+
.replace(/(?<!&)#(?=\d+\b)/g, `#${zw}`)
213+
.replace(/\bgh-(?=\d+\b)/gi, `$&${zw}`)
214+
.replace(/\/(issues|pull|discussions)\/(?=\d)/g, `/$1/${zw}`)
215+
.slice(0, 65000);
207216
if (!body.startsWith(marker)) {
208217
core.setFailed('The check job produced no report; nothing posted.');
209218
return;

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ For an important PR, a maintainer adds the `final-check` label.
6565
[`final-check.yml`](.github/workflows/final-check.yml) then builds everything
6666
`pages.yml` would publish from the PR and runs TechEngine's Tier 0-3
6767
verification of the changed records. TechEngineBot posts one comment with the
68-
verdict; adding the label again updates that comment.
68+
verdict; adding the label again updates that comment. The comment can't mention
69+
anyone or reference other issues: `@` is dropped and `#123` links are broken.
6970

7071
New and refreshed records come from
7172
[`collect.yml`](.github/workflows/collect.yml), which a maintainer runs by hand

0 commit comments

Comments
 (0)