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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

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).

Notes

opened this

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: allows permits a GET of that exact URL only when the pull is the token's own. pullNumberIn now also recognises the page path /<owner>/<repo>/pulls/<n>/…, so src/http/contribute_gate.ts can 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.

Closes #12166

commented

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: allows permits a GET of that exact URL only when the pull is the token's own. pullNumberIn now also recognises the page path /<owner>/<repo>/pulls/<n>/…, so src/http/contribute_gate.ts can 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.

commented

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 one lines computation. 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: getRepoById is now a top-level import instead of the inline await import.

I changed nothing else, and I disagree with nothing in the review.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs