Skip to content

feat(token): let tools request a PMC-scoped token through the browser - #264

Merged
raboof merged 5 commits into
apache:mainfrom
potiuk:token-authorize
Oct 5, 2026
Merged

raboof merged 5 commits into
apache:mainfrom
potiuk:token-authorize

Conversation

@potiuk

@potiuk potiuk commented Sep 25, 2026

Copy link
Copy Markdown
Member

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

  1. The tool listens on 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.
  2. The user logs in via ASF OAuth if needed (MFA included), sees the PMC, scope and requesting port, and clicks Approve or Deny (CSRF-protected form).
  3. The browser is redirected to the tool with ?code=…&state=… (or ?error=access_denied).
  4. The tool POSTs {code, code_verifier} to /users/token/exchange and 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_uri must be a loopback IP literal (127.0.0.1 or [::1]) with a port; localhost is 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/token uses, so its lifetime and revocation are unchanged: it dies with the login, and logging out revokes it.

Behaviour changes

  • PMC tokens are now actually limited to their PMC.
    Today a PMC write token authenticates as the full user, and every record ACL checks req.user.pmcs, so it can edit records of all the owner's PMCs — for a security-team member, of every PMC.
    ensureAuthenticated now narrows req.user.pmcs to the token's PMC.
    This applies to the existing write and allocate tokens as well.
  • New read scope: GET/HEAD on /cve5/CVE-* and /cve5/json/CVE-* only. Listed on /users/token next to allocate and write.
  • /users/token fills in missing tokens instead of resetting the map when session.token is unset, so a token issued through the new flow survives a later visit to that page.

The scope checks moved from app.js into custom/tokenauthorize.js (same messages for allocate and write) so they can be unit-tested.

Testing

  • unittest/tokenauthorize.js (added to npm 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.
  • The consent page renders, and escapes user-supplied values.
  • Not yet run end to end against a dev instance (Mongo + oauth.apache.org).
    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.

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
@potiuk

potiuk commented Sep 26, 2026

Copy link
Copy Markdown
Member Author

End-to-end test against the reference client (apache/magpie#1388)

Ran this PR (c293f25) against the client in apache/magpie#1388 (3fd4e77c), using the real vulnogram-api-setup / vulnogram-api-check CLIs and a headless Chromium standing in for the operator.

Setup: Vulnogram (node app.js, TLS with a self-signed cert), in-memory MongoDB seeded with one airflow and one tomcat record, and a local mock OIDC provider in place of mfa.apache.org, configured through the OAUTH_* env vars from #251. The mock user is on the airflow and tomcat PMCs. The real ASF login/MFA page is not part of this run; everything after the ID token is the real code.

Result: 30/30 checks pass. Also npm run unittest passes (tokenauthorize: all tests passed).

summary

read token, starting logged out

ASF login (mock) Consent Loopback callback


  • Unauthenticated /users/token/authorize goes 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.
  • read token: GET own-PMC record → 200; POST to a record → 403; /allocatecve → 403; the other PMC's record page → refused; /users/token/authorize with the Bearer token → redirect to login (tokens cannot mint tokens).
  • Session file has pmc/scope, mode 600; vulnogram-api-check prints valid / 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
@potiuk

potiuk commented Sep 26, 2026

Copy link
Copy Markdown
Member Author

I added a short design doc for this change: docs/design/browser-token-authorize.md.

It is written to support two kinds of review:

  1. Reviewing the design. The Assumptions (A1–A7) and Alternatives considered sections are where I'd most like pushback. For example: is a loopback redirect plus user consent enough to identify "a tool on this machine"? Is it OK that codes live in process memory? Is a session-bound lifetime the right trade-off? If an assumption is wrong, the design is wrong, however good the code is.
  2. Checking the implementation against the design. The Invariants table (I1–I17) lists testable claims, each mapped to the code that enforces it and the test that covers it (or marked "not covered"). You don't have to trace these by hand: give the doc and this PR's diff to your coding agent, ask it to verify each invariant against the code, and ask it to flag any code path the invariants don't cover. I'd be glad to see what your agents find.

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.

Comment thread custom/tokenauthorize.js Resolved
Comment thread docs/design/browser-token-authorize.md Resolved
Comment thread docs/design/browser-token-authorize.md Resolved
Comment thread docs/design/browser-token-authorize.md Resolved
Comment thread docs/design/browser-token-authorize.md Resolved
Comment thread README-ASF.md Resolved
Comment thread docs/design/browser-token-authorize.md Resolved
potiuk added 2 commits October 5, 2026 15:54
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
@potiuk

potiuk commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

@raboof I've pushed two commits since your approval, so could you take another look?

  • 73ec7ed: allocate can now be requested through the browser flow, plus the design-doc fixes from your comments.
  • 86e258a: POST /allocatecve now returns JSON to Bearer callers. It returns {"cve_ids": [...]} on success, 202 when the request goes to security@ by mail, and JSON errors otherwise. That way a tool gets the CVE ID back directly instead of scraping an HTML link. The browser form is unchanged.

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?

@potiuk

potiuk commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

End-to-end test: allocate scope and JSON from /allocatecve

Ran this PR (86e258a) against the updated Magpie client in apache/magpie#1388 (884f99b7), using the real vulnogram-api-* CLIs. Current main (8b0f147) ran alongside to check the fallbacks.

Setup: node app.js in development mode (TLS with the test cert from unittest/), MongoDB in memory, and a mock OIDC provider in place of mfa.apache.org, configured through the OAUTH_* env vars. The mock user is on the airflow, tomcat and zeppelin PMCs. In development mode Vulnogram uses its fake CVE Services response (CVE-2000-… IDs), so no real IDs were reserved and no mail was sent. Headless Chrome played the operator: the CLI handed it the approval URL, and it logged in through the mock provider and clicked Approve or Deny.

This PR

Browser approval of an allocate token: the consent page names the scope and what it allows:

consent

setup

Allocation with no form: POST /allocatecve with the Bearer token returns 200 {"cve_ids": [...]}. A token for another PMC and an empty title are both refused, and nothing is allocated:

allocate

The new record has owner airflow, state RESERVED, the title, and the report thread from messageid/listid:

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:

zeppelin

Deny on the consent page: the callback gets error=access_denied and no token is issued:

deny

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:

old

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:

old allocate

Not covered: the real mfa.apache.org login and MFA, and live CVE Services.

@raboof raboof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now LGTM. Cool feature!

@raboof

raboof commented Oct 5, 2026

Copy link
Copy Markdown
Member

does merging this redeploy cveprocess.apache.org automatically, or does it need a separate deployment step?

It's mostly deployed automatically but I think still needs a manual nudge for the final step, I can take care of that.

@raboof
raboof merged commit 9ffa163 into apache:main Oct 5, 2026
3 checks passed
@potiuk

potiuk commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

Cool. I already merged support for it in Magpie and will test it on real case now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants