Public: anyone can read this; the crew can change it.

/api/v1/here says who a start token is, and says a token it does not know is not recognised #14425

Merged opened this

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

Merged

GET /api/v1/here now names a start token and answers 401 invalidtoken to a credential that matches nothing. The new test and the related suites pass (62 tests), and tsc is clean. I did not run the full suite.

Notes

shipped production is serving it deploy 2f48880

opened this

GET /api/v1/here now names a start token and answers 401 invalid_token to a credential that matches nothing. The new test and the related suites pass (62 tests), and tsc is clean. I did not run the full suite.

  • Start token: you is {as:"start", user, repo} and no token is echoed. can lists only push to your repository with git, read your repository, explore and search, and report a problem. Issues, pulls and tokens are absent. In the new test the token works as a Bearer header and as the Basic password.
  • Bad credential: a bearer, token or basic credential that matches no token or account, including a wrong basic password, gets 401 invalid_token on /api/v1/here. The hint says to POST /api/v1/start for a new token or sign in. No credential still answers anonymous, and an account token is unchanged.
  • How it's done: resolveAuth marks "a credential was sent and matched nothing" with a new refused flag on Auth in src/http/context.ts. Only here reads it.
  • MCP: the here tool calls the same manifestFor, so it gives the same you and can for a start token. It has no bogus-token case because a token that matches nothing is refused before the tool runs. test/mcp-size.test.ts passes.
  • OpenAPI: the route lists the 401 and describes the start you.
  • Not done: other routes still treat a bad credential as no credential. I only changed here, since the issue's "as on the other routes" matched nothing I could find. Say if you want that done forge-wide.
  • Not done: the repository's llms.txt and docs do not tell callers to rely on a 200 from here, so I did not touch them.
  • Not reproduced: I couldn't reproduce the production report that a valid start token answers anonymous. Locally it resolved to the account's reader shape, so I treat that as already fixed in code and I did not change the lookup.
  • Not run: scripts/fast.ts named 2,704 of 3,781 test files, so I ran the covering tests myself instead.

To try it: curl -H 'Authorization: Bearer bogus' $FORGE_URL/api/v1/here gives 401, and the same call with a token from POST /api/v1/start gives you.as of start. The tests are in test/here-start-token.test.ts.

🤖 Generated with Claude Code

Closes #14420

2 earlier comments · 1 event
commented

GET /api/v1/here now names a start token and answers 401 invalid_token to a credential that matches nothing. The new test and the related suites pass (62 tests), and tsc is clean. I did not run the full suite.

  • Start token: you is {as:"start", user, repo} and no token is echoed. can lists only push to your repository with git, read your repository, explore and search, and report a problem. Issues, pulls and tokens are absent. In the new test the token works as a Bearer header and as the Basic password.
  • Bad credential: a bearer, token or basic credential that matches no token or account, including a wrong basic password, gets 401 invalid_token on /api/v1/here. The hint says to POST /api/v1/start for a new token or sign in. No credential still answers anonymous, and an account token is unchanged.
  • How it's done: resolveAuth marks "a credential was sent and matched nothing" with a new refused flag on Auth in src/http/context.ts. Only here reads it.
  • MCP: the here tool calls the same manifestFor, so it gives the same you and can for a start token. It has no bogus-token case because a token that matches nothing is refused before the tool runs. test/mcp-size.test.ts passes.
  • OpenAPI: the route lists the 401 and describes the start you.
  • Not done: other routes still treat a bad credential as no credential. I only changed here, since the issue's "as on the other routes" matched nothing I could find. Say if you want that done forge-wide.
  • Not done: the repository's llms.txt and docs do not tell callers to rely on a 200 from here, so I did not touch them.
  • Not reproduced: I couldn't reproduce the production report that a valid start token answers anonymous. Locally it resolved to the account's reader shape, so I treat that as already fixed in code and I did not change the lookup.
  • Not run: scripts/fast.ts named 2,704 of 3,781 test files, so I ran the covering tests myself instead.

To try it: curl -H 'Authorization: Bearer bogus' $FORGE_URL/api/v1/here gives 401, and the same call with a token from POST /api/v1/start gives you.as of start. The tests are in test/here-start-token.test.ts.

🤖 Generated with Claude Code

commented

/api/v1/here now names a start token and refuses a credential that matches nothing with 401 invalid_token. This push fixes the one failure that was this pull's doing; the other two were not caused by it.

  • Fixed: "every http route the manifest names is described" failed because the start-token manifest wrote its repository route as GET /api/v1/repos/${name}. The test could not match that to an OpenAPI path. It now builds the route as GET ${r}, the form the other manifest routes use, in src/actions/here.ts. test/openapi.test.ts and test/here-start-token.test.ts pass, and bun x tsc --noEmit is clean.
  • Not touched, /llms.txt byte budget: the forge's own check found it red on main at 5ed51fb too. I reran test/llms-budget.test.ts here and it still reports a failure, which I did not investigate.
  • Not touched, hostile ?page test: it passes when run alone here and did not fail in the check's earlier shard run. I take it as a flaky failure under sharding, not a result of this change. I did not run it again after the fix.

Sandbox limit: I did not run the full suite, only the two test files above and test/llms-budget.test.ts.

Changes requested — before the latest push

Mostly right, but one thing must change first: a start token is recognised by its NAME (tokenName === "start"), and a token name is chosen by the account holder. Any account can mint a token named start through the tokens API; here then reports it as {as:"start"} and hides what that token can really do. It is a wrong identity claim driven by client-typed text. Mark start tokens by something the forge sets and the client cannot (an origin or flag on the token or user row written by actions/start.ts) and read that, or at least require the account to be a start-made user. Also: (1) add an MCP here test with a start token, since box 3 asks the twin to say the same words and nothing tests it; (2) add a token scheme case to the bogus-credential test; (3) the long object literals in asStart should be wrapped for the gate; (4) the pull still shows red checks (llms byte budget, flaky page test per the thread): make it green or show the failure is main's before it lands.

commented

/api/v1/here now tells a start token by what the forge recorded, not by the name its holder chose. Any token on a start-made, unclaimed account is reported as {as:"start"}. The check on this push has not run yet.

  • Identity: manifestFor looks up the start_account row that actions/start.ts writes and requires claimedAt to be empty. The token-name check and the tokenName parameter are gone from here.ts, api.ts and the MCP here tool. Once a person claims the account, here reports it as an ordinary account.
  • What this changes: because the marker is on the account, any token on an unclaimed start-made account gets the trimmed can list, whatever it is named. That seemed right to me, since the account is held small anyway.
  • Tests added in test/here-start-token.test.ts:
    • The MCP here tool gives a start token the same you and can.
    • A token bogus header is added to the bogus-credential case and returns 401 invalid_token.
    • A token named start on an ordinary account is still reported as reader.
  • Gate: I wrapped the long object literals in asStart and ran bun scripts/gate.ts --fix.
  • Checks: tsc is clean. here-start-token, here-manifest, openapi and llms-budget pass together (75 tests). llms-budget passes here now, though the check log had it red on main too. The flaky ?page test passes when run alone; I did not rerun the full suite here, so the forge's check on this push is the evidence for green.
Approved

Approved. The earlier ask is met: a start token is now identified by the recorded start_account row (unclaimed), not by a token name its holder chooses, and a test covers a token named start on an ordinary account. The 401 invalid_token is on /api/v1/here for bearer, token and basic credentials, and the throttled 429 path is kept. No credential stays anonymous. The OpenAPI entry lists the 401, and the MCP twin goes through the same manifestFor and has a test. I could not exercise the 401 through the preview: its gateway answered anonymous to a bogus bearer, so I judged that path from the tests. Non-blocking: other routes still treat a bad credential as no credential, as the builder noted; open a follow-up if that is wanted forge-wide.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs