Public: anyone can read this; the crew can change it.
The OAuth consent page lists, in plain words, what an agent token can do and for how long #14089
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/14069-the-oauth-consent-page-lists-in-plain-wo → main 6 commits fork 3 threads · 3 unresolved
3 files
changed +37
−12
src/core/oauth.ts +3 −1
| @@ -243,7 +243,9 @@ export function parseAuthRequest( | ||
| 243 | 243 | return err("The code_challenge is not a base64url SHA-256."); |
| 244 | 244 | const state = get("state"); |
| 245 | 245 | if (state.length > STATE_MAX) return err("The state is too long."); |
| 246 | // Scopes the forge does not offer are ignored, as they always were. | |
| 246 | const unknown = get("scope").split(/\s+/).find((v) => v !== "" && !Object.hasOwn(SCOPE_WORDS, v)); | |
| 247 | if (unknown !== undefined) | |
| 248 | return err("This forge does not offer the scope " + JSON.stringify(unknown.slice(0, 40)) + "."); | |
| 247 | 249 | const asked = get("scope").split(/\s+/).find(isOAuthScope); |
| 248 | 250 | const oidc = oidcScopes(get("scope")); |
| 249 | 251 | const openid = oidc.includes("openid"); |
src/web/pages/oauth.ts +13 −3
| @@ -111,6 +111,12 @@ function signInConsent(request: AuthRequest, values: Params): Html { | ||
| 111 | 111 | </div>`; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | /** The calendar day a token minted now would stop working, in words. */ | |
| 115 | const endsOn = (lifetime: string): string => { | |
| 116 | const seconds = LIFETIMES[lifetime] ?? 0; | |
| 117 | return new Date(Date.now() + seconds * 1000).toISOString().slice(0, 10); | |
| 118 | }; | |
| 119 | ||
| 114 | 120 | function consent(ctx: Ctx, request: AuthRequest, values: Params): Html { |
| 115 | 121 | if (request.signInOnly) return signInConsent(request, values); |
| 116 | 122 | const host = new URL(request.redirectUri).host; |
| @@ -150,10 +156,14 @@ function consent(ctx: Ctx, request: AuthRequest, values: Params): Html { | ||
| 150 | 156 | <label for="f-lifetime">Lasts</label> |
| 151 | 157 | <select class="input" id="f-lifetime" name="lifetime"> |
| 152 | 158 | <option value="never" selected>Until I revoke it</option> |
| 153 | <option value="year">A year</option> | |
| 154 | <option value="month">30 days</option> | |
| 155 | <option value="day">A day</option> | |
| 159 | <option value="year">A year (until ${endsOn("year")})</option> | |
| 160 | <option value="month">30 days (until ${endsOn("month")})</option> | |
| 161 | <option value="day">A day (until ${endsOn("day")})</option> | |
| 156 | 162 | </select> |
| 163 | <p class="muted small"> | |
| 164 | Revoke it any time under | |
| 165 | <a href="/settings/grants">Connected agents</a>. | |
| 166 | </p> | |
| 157 | 167 | </div> |
| 158 | 168 | <div class="form-actions"> |
| 159 | 169 | ${btn("Allow", { variant: "primary", name: "decision", value: "allow" })} |
test/oauth-consent-words.test.ts +21 −8
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /** |
| 2 | * The consent page says who asks, where it returns, and what each scope means; unknown scopes are | |
| 3 | * ignored. | |
| 2 | * The consent page says who asks, where it returns, and what each scope means; an unknown scope is | |
| 3 | * refused. | |
| 4 | 4 | */ |
| 5 | 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 6 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| @@ -75,15 +75,19 @@ for (const scope of Object.keys(SCOPE_WORDS)) { | ||
| 75 | 75 | }); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | test("an unknown scope is ignored, never refused, and never granted", async () => { | |
| 79 | for (const scope of ["admin", "ro offline_access", "rw nonsense", "offline_access"]) { | |
| 78 | test("an unknown scope is refused, never granted", async () => { | |
| 79 | for (const scope of ["admin", "ro offline_access", "rw nonsense", "offline_access", "constructor"]) { | |
| 80 | 80 | const res = await get(scope); |
| 81 | expect(res.status).toBe(200); | |
| 81 | expect(res.status).toBe(400); | |
| 82 | 82 | const body = await res.text(); |
| 83 | expect(body).toContain('name="grant"'); | |
| 83 | expect(body).not.toContain('name="grant"'); | |
| 84 | expect(body).toContain("does not offer the scope"); | |
| 84 | 85 | } |
| 85 | const body = await (await get("rw offline_access")).text(); | |
| 86 | expect(body).toMatch(/value="rw"\s+checked/); | |
| 86 | }); | |
| 87 | ||
| 88 | test("no scope at all falls back to read-only", async () => { | |
| 89 | const body = await (await get("")).text(); | |
| 90 | expect(body).toMatch(/value="ro"\s+checked/); | |
| 87 | 91 | }); |
| 88 | 92 | |
| 89 | 93 | test("a hostile client name is escaped", async () => { |
| @@ -91,3 +95,12 @@ test("a hostile client name is escaped", async () => { | ||
| 91 | 95 | expect(body).not.toContain("<img src=x"); |
| 92 | 96 | expect(body).toContain("<img src=x"); |
| 93 | 97 | }); |
| 98 | ||
| 99 | test("the page shows when each lifetime ends and links to revoking", async () => { | |
| 100 | const body = await (await get("ro")).text(); | |
| 101 | const day = (s: number) => new Date(Date.now() + s * 1000).toISOString().slice(0, 10); | |
| 102 | expect(body).toContain(`A year (until ${day(365 * 86_400)})`); | |
| 103 | expect(body).toContain(`30 days (until ${day(30 * 86_400)})`); | |
outdated
Assert the revoke link target /settings/grants once fixed; this test pins the wrong page. |
||
| 104 | expect(body).toContain("Until I revoke it"); | |
| 105 | expect(body).toContain('href="/settings/grants">Connected agents'); | |
| 106 | }); | |
outdated
This does not test refusal: it only checks SCOPE_WORDS has entries and that 'admin' falls back to ro. Issue box 3 needs an unknown scope refused, with a test that fails without it, or the box stays open. |
new above
offline
Wrong destination: OAuth grants are revoked at /settings/grants (Connected agents), not /settings/tokens (Access codes). Fix the href and label. Principle 8 (plain words): 'Revoke it any time under Connected agents.'