Repository navigation
feat(token): let tools request a PMC-scoped token through the browser - #264
Conversation
A command-line tool can now get an API token without the user copying it from /users/token. The tool opens /users/token/authorize with a PMC, a scope (read or write), a loopback redirect_uri, a state and a PKCE challenge. The user logs in (MFA included), sees what is asked for, and approves or denies. On approval the browser is redirected to the tool with a one-time code, which the tool exchanges with its PKCE verifier at POST /users/token/exchange. This is the OAuth 2.0 native-app flow (RFC 8252 with RFC 7636 PKCE), so the token never appears in a URL or in the browser history. PMC tokens are now limited to their PMC: a token acts as its owner with pmcs narrowed to the token's PMC, so the record ACLs keep it away from the owner's other PMCs (and from the security team's access to all of them). This tightens the existing write and allocate tokens too. Adds a `read` scope (GET/HEAD on record URLs only), listed on /users/token next to allocate and write. /users/token now fills in missing tokens instead of resetting the map, so a token issued through the browser flow survives a later visit to that page. Refs apache#246 Generated-by: Claude Opus 5
End-to-end test against the reference client (apache/magpie#1388)Ran this PR ( Setup: Vulnogram ( Result: 30/30 checks pass. Also
|
| ASF login (mock) | Consent | Loopback callback |
|---|---|---|
![]() |
![]() |
![]() |
- Unauthenticated
/users/token/authorizegoes through login and lands back on the consent page with the parameters intact. - The callback carries only
code+state; the token comes back from/users/token/exchange. - Replaying the used code →
400 invalid_grant; a made-up code →400. readtoken:GETown-PMC record → 200;POSTto a record → 403;/allocatecve→ 403; the other PMC's record page → refused;/users/token/authorizewith the Bearer token → redirect to login (tokens cannot mint tokens).- Session file has
pmc/scope, mode 600;vulnogram-api-checkprintsvalid/read token for airflow.
write token (already logged in), /users/token, Deny, invalid requests, logout
write — goes straight to consent; different token from read; /allocatecve → 403.
/users/token — lists read; visiting it keeps the browser-issued tokens (tokens masked in the screenshot).
Deny — callback gets error=access_denied; the CLI exits 1 and writes nothing.
Refused requests — localhost redirect_uri, non-member PMC, allocate scope, plain PKCE:
Logout revokes — both tokens report expired afterwards.
Not covered: the real mfa.apache.org login and MFA, and a write that actually modifies a record.
Describes the problem, the RFC 8252 + PKCE flow, the assumptions it rests on, and numbered invariants mapped to code and tests, so the design can be reviewed on its own and the implementation checked against it. Generated-by: Claude Opus 5
|
I added a short design doc for this change: It is written to support two kinds of review:
I think this is likely how reviews with AI in the loop should work. The author states the intent, assumptions and invariants explicitly. Human reviewers spend their attention on whether those are right: the problem, the trade-offs, the trust boundaries. Agents do the systematic work of checking that the code matches what the design says. As more code is written with AI help, reviewing line by line scales poorly. Reviewing a design and having agents check the code against it scales much better. Generative AI disclosure: drafted with Claude Code (Claude Opus 5); reviewed and verified by the author. |
A tool can already allocate a CVE by opening /allocatecve in the browser, but an allocate token from the browser flow lets it run the whole allocation without the user copying a token by hand. Also drop the CORS remark from A6 (it is the Authorization header not being sent by browsers that matters), drop the shared-store open question, and say what the end-to-end run did and did not cover. Generated-by: Claude Opus 5
POST /allocatecve answered every request with HTML, so a tool using a Bearer token had to scrape the CVE ID out of a link. Requests with a Bearer token now get JSON: the allocated IDs on success, 202 when the request was mailed to the security team instead, and a JSON error with a matching status otherwise. If saving the record fails, the reserved ID is still returned. The browser form is unchanged. Generated-by: Claude Opus 5
|
@raboof I've pushed two commits since your approval, so could you take another look?
I'm testing it end to end against a local Vulnogram with the draft Magpie client in apache/magpie#1388. One question about rollout: does merging this redeploy cveprocess.apache.org automatically, or does it need a separate deployment step? |
End-to-end test:
|
| Editor | Source |
|---|---|
![]() |
![]() |
PMC that cannot allocate directly (202), and Deny
zeppelin is excluded in pmcstrustedascna, so the request is mailed to security@ (logged only, in dev mode) and the client exits 5 without an ID:
Deny on the consent page: the callback gets error=access_denied and no token is issued:
Current main, for the fallbacks
The token-free probe (POST /users/token/exchange with a made-up code) gets 302 to /users/login instead of 400 invalid_grant, so the client reports unsupported. --scope allocate stops right away and points at the form; --scope write falls back to copying the token from /users/token:
An allocate token copied from /users/token gets HTML from /allocatecve. The check reports unsupported, and a successful allocation still yields the ID from the record link:
Not covered: the real mfa.apache.org login and MFA, and live CVE Services.
It's mostly deployed automatically but I think still needs a manual nudge for the final step, I can take care of that. |
|
Cool. I already merged support for it in Magpie and will test it on real case now. |


























Lets a command-line tool obtain a PMC-scoped API token through the browser, approved by the user, instead of having the user copy one from
/users/token.Refs #246.
Flow
http://127.0.0.1:<port>/, then opens/users/token/authorize?pmc=<pmc>&scope=read|write&redirect_uri=http://127.0.0.1:<port>/callback&state=<state>&code_challenge=<S256>&code_challenge_method=S256.?code=…&state=…(or?error=access_denied).{code, code_verifier}to/users/token/exchangeand gets{access_token, token_type, pmc, scope}back.This is the OAuth 2.0 native-app pattern (RFC 8252, with PKCE per RFC 7636):
the token never lands in a URL or the browser history, and a local process that catches the redirect cannot redeem the code without the verifier.
Codes are single-use (spent on the first attempt, right or wrong) and valid for 60 seconds.
redirect_urimust be a loopback IP literal (127.0.0.1or[::1]) with a port;localhostis refused, as RFC 8252 §8.3 recommends.A Bearer token cannot reach
/users/token/authorize, so tokens cannot mint tokens.The issued token is an ordinary session-bound token, stored in the same
session.tokens[pmc][scope]map/users/tokenuses, so its lifetime and revocation are unchanged: it dies with the login, and logging out revokes it.Behaviour changes
Today a PMC
writetoken authenticates as the full user, and every record ACL checksreq.user.pmcs, so it can edit records of all the owner's PMCs — for a security-team member, of every PMC.ensureAuthenticatednow narrowsreq.user.pmcsto the token's PMC.This applies to the existing
writeandallocatetokens as well.readscope:GET/HEADon/cve5/CVE-*and/cve5/json/CVE-*only. Listed on/users/tokennext toallocateandwrite./users/tokenfills in missing tokens instead of resetting the map whensession.tokenis unset, so a token issued through the new flow survives a later visit to that page.The scope checks moved from
app.jsintocustom/tokenauthorize.js(same messages forallocateandwrite) so they can be unit-tested.Testing
unittest/tokenauthorize.js(added tonpm run unittest): redirect-URI validation, request validation (membership, security-team override, scope, state, PKCE parameters), code issue/redeem (PKCE match, single use, expiry, wrong verifier spends the code), scope checks per method and URL, and user narrowing.A reference client is in apache/magpie (
vulnogram-api-setup --pmc <pmc> [--scope read]), which I'd like to use for that round-trip before merge.Generative AI disclosure: drafted with Claude Code (Claude Opus 5); reviewed and verified by the author.