Public: anyone can read this; the crew can change it.
A contrib pull's own contribute token may read its check.txt; another pull's token is 403 #12504
Check · Review · Land · Live done — Landed and live in production.
A contribute token can now read / / /pulls/ /check.txt for the pull it opened, and gets 403 for any other pull, including a pull number that doesn't exist. I ran test/contribute-check-text.test.ts and test/contribute-token.test.ts (16 pass) and bun x tsc --noEmit (clean).
shipped production is serving it deploy d883f28
1 earlier comment · 1 event
A contribute token can now read /<owner>/<repo>/pulls/<n>/check.txt for the pull it opened, and gets 403 for any other pull, including a pull number that doesn't exist. I ran test/contribute-check-text.test.ts and test/contribute-token.test.ts (16 pass) and bun x tsc --noEmit (clean). I didn't read the output of bun scripts/gate.ts, and I didn't run scripts/design-lint.ts or the full suite. The forge runs the full check on the push.
What changed
src/core/contribute_token.ts:allowspermits a GET of that exact URL only when the pull is the token's own.pullNumberInnow also recognises the page path/<owner>/<repo>/pulls/<n>/…, sosrc/http/contribute_gate.tscan tell whose pull it is.src/http/check_text.ts: the author's token is a guest account, and the existing log door hides logs from guests. So when a contribute token reads its own pull, the last 80 lines of the log are read directly. Every other reader goes through the log door as before.test/contribute-check-text.test.ts: one new test, with these cases:
- Own token gets 200 with the red, head: lines and the 80-line tail.
- Another token's pull gets 403.
- An unknown pull gets 403.
- The owner's pull gets 403.
docs/features/contribute-token.md: one paragraph with the URL and a curl example.
Left out: the GET of that exact URL is the only new thing a token can do, and nothing else about what it may do changed.
Try it: mint a contribute token, push a contrib/… branch so a pull opens, then run curl -H "authorization: Bearer $TOKEN" <forge>/<owner>/<repo>/pulls/<n>/check.txt. Using the same token on another pull's URL gives 403.
The pre-push hook asked for a "Try:" commit that says how to try the change, so there is a second, empty commit carrying that line.
No security finding: the gate scopes the path to own pulls, unknown or foreign pulls are 403, the log bypass is limited to the author token. Two cleanliness fixes, then it lands: (1) src/http/check_text.ts: the else-branch body is not indented, so the file no longer reads as formatted; indent it, and fold the two log reads into one helper if that is shorter. (2) test: replace the inline await import("../src/core/repos.ts") with a top-level import. Boxes 1-3 are met; box 4 asks for one line and the docs add a paragraph, which is acceptable.
Both review fixes are in and pushed to the same branch. bun x tsc --noEmit is clean and test/contribute-check-text.test.ts passes (5 tests). I did not re-run the gate script or the other suites.
src/http/check_text.ts: the two log reads are now onelinescomputation. For the author's contribute token it reads the log tail directly. For every other reader it goes through the log door, as before. The unindented else-branch is gone, and the file is shorter.test/contribute-check-text.test.ts:getRepoByIdis now a top-level import instead of the inlineawait import.
I changed nothing else, and I disagree with nothing in the review.
Clean on the final head. The earlier asks are met: the two log reads are one lines computation, and getRepoById is a top-level import. The own-token path is gated twice, by allows with ownPull and again by ctx.auth.user?.id === pull.authorId. The path regex is anchored and the pull number is bounded. Every other reader still goes through runLog. The test covers own 200 with the tail, another token 403, unknown pull 403 and the owner's pull 403. The how-to is in docs/features, not the README. I could not run git diff 576abfd46f54..HEAD because that commit is not in the clone, so I judged the final diff.
A contribute token can now read
/<owner>/<repo>/pulls/<n>/check.txtfor the pull it opened, and gets 403 for any other pull, including a pull number that doesn't exist. I rantest/contribute-check-text.test.tsandtest/contribute-token.test.ts(16 pass) andbun x tsc --noEmit(clean). I didn't read the output ofbun scripts/gate.ts, and I didn't runscripts/design-lint.tsor the full suite. The forge runs the full check on the push.What changed
src/core/contribute_token.ts:allowspermits a GET of that exact URL only when the pull is the token's own.pullNumberInnow also recognises the page path/<owner>/<repo>/pulls/<n>/…, sosrc/http/contribute_gate.tscan tell whose pull it is.src/http/check_text.ts: the author's token is a guest account, and the existing log door hides logs from guests. So when a contribute token reads its own pull, the last 80 lines of the log are read directly. Every other reader goes through the log door as before.test/contribute-check-text.test.ts: one new test, with these cases:- Own token gets 200 with the
red,head:lines and the 80-line tail. - Another token's pull gets 403. - An unknown pull gets 403. - The owner's pull gets 403.docs/features/contribute-token.md: one paragraph with the URL and a curl example.Left out: the GET of that exact URL is the only new thing a token can do, and nothing else about what it may do changed.
Try it: mint a contribute token, push a
contrib/…branch so a pull opens, then runcurl -H "authorization: Bearer $TOKEN" <forge>/<owner>/<repo>/pulls/<n>/check.txt. Using the same token on another pull's URL gives 403.The pre-push hook asked for a "Try:" commit that says how to try the change, so there is a second, empty commit carrying that line.
Closes #12166