Skip to content

Commit 7337ace

Browse files
committed
wip: real-route pins for a disabled client and a suspended key, and the changeset
Claude-Session: https://claude.ai/code/session_01QUs3BuLtRmSkjNPDYrwA9T Co-authored-by: Claude <noreply@anthropic.com>
1 parent ea6dbff commit 7337ace

3 files changed

Lines changed: 309 additions & 195 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
'@objectstack/core': patch
4+
'@objectstack/platform-objects': patch
5+
---
6+
7+
fix(plugin-auth): disabling an OAuth client refuses its already-issued tokens on their next call, and a platform administrator's revoke of someone else's API key holds against its owner
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
**OAuth clients.** Disabling a client (the Disable action of `sys_oauth_application`, `POST /api/v1/auth/admin/oauth2/toggle-disabled`) refused it a new token, but the MCP door kept serving the access tokens it already held until they expired, up to an hour. The door now reads the client on every call, beside the consent it already reads, and refuses with the same `401` a withdrawn grant gets when the client is disabled, when its row is gone, or when the read fails. Disabling is a pause: the consent and the refresh token stay, so enabling the client again serves them again. To end the grant, withdraw it (`POST /api/v1/auth/authorized-clients/withdraw`, or the admin door) or call `/oauth2/revoke`. Each MCP call now makes two indexed reads (the client by `client_id`, then the consent) instead of one.
13+
14+
**API keys.** A revoked key is restorable, and until now its owner could restore a key an administrator had revoked the moment it was revoked. When a platform administrator revokes a key that is not theirs, `sys_api_key.revoked_reason` now records `administrator_suspended`, and only a platform administrator can restore that key. The owner's restore is refused `403 PERMISSION_DENIED`, naming the reason, and the key door's `403 API_KEY_REVOKED` says who can restore it. Restoring clears the reason, as before, and the same key works again with no re-issue. A host that stops a key itself writes the same value in the system context, beside `revoked: true`. The owner's own revoke still records no reason. An administrator's revoke never replaces a reason the key already carries, so a key revoked because its owner's membership ended stays restorable by no one. One multi-row revoke that matches both a key this rule stamps and a key that already carries a reason is refused whole with `400 VALIDATION_ERROR`; revoke those keys separately. The new select option and its description are translated in every shipped locale.
15+
16+
This does not stop a person from minting a new key of their own. A key acts as its owner, so stopping an agent for good takes a credential its owner cannot re-issue.

‎packages/qa/dogfood/test/api-key-owner-revoke.dogfood.test.ts‎

Lines changed: 92 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -64,64 +64,66 @@ import { describe, it, expect, beforeAll, afterAll } from 'vitest';
6464
import { type VerifyStack } from '@objectstack/verify';
6565
import { bootShowcase } from './showcase-boot.js';
6666

67-
describe('#8053: a member revokes their OWN sys_api_key', () => {
68-
let stack: VerifyStack;
69-
/** The seeded platform admin — used ONLY to mint the cross-owner key. */
70-
let adminToken: string;
71-
/** The persona under test: an ordinary member, no roles, no grants. */
72-
let memberToken: string;
73-
74-
const MEMBER_EMAIL = 'apikey.owner.8053@verify.test';
75-
76-
/** Mint a key through the ONE mint path, as whoever holds `token`. */
77-
const mintKey = async (token: string, name: string): Promise<{ id: string; raw: string }> => {
78-
const res = await stack.apiAs(token, 'POST', '/keys', { name });
79-
expect(res.status, await res.clone().text()).toBe(201);
67+
// The one showcase boot every describe below shares: the seeded platform
68+
// administrator, one ordinary member, and the helpers that drive the real routes.
69+
let stack: VerifyStack;
70+
/** The seeded platform admin — in the #8053 describe used ONLY to mint the cross-owner key. */
71+
let adminToken: string;
72+
/** The persona under test: an ordinary member, no roles, no grants. */
73+
let memberToken: string;
74+
75+
const MEMBER_EMAIL = 'apikey.owner.8053@verify.test';
76+
77+
/** Mint a key through the ONE mint path, as whoever holds `token`. */
78+
const mintKey = async (token: string, name: string): Promise<{ id: string; raw: string }> => {
79+
const res = await stack.apiAs(token, 'POST', '/keys', { name });
80+
expect(res.status, await res.clone().text()).toBe(201);
81+
const body: any = await res.json();
82+
expect(body?.data?.id).toBeTruthy();
83+
expect(body?.data?.key).toBeTruthy();
84+
return { id: String(body.data.id), raw: String(body.data.key) };
85+
};
86+
87+
/**
88+
* Does this key still authenticate? Asked through a real read with NO bearer
89+
* token, so the key is the only credential present. `showcase_task` is the
90+
* card's own probe and is readable by a member via `showcase_member_default`
91+
* — deliberately NOT `sys_api_key`, so a permission change on the object
92+
* under test can never be mistaken for a credential verdict.
93+
*/
94+
const keyStillAuthenticates = async (raw: string): Promise<boolean> => {
95+
const res = await stack.api('/data/showcase_task?$top=1', { headers: { 'x-api-key': raw } });
96+
if (res.status === 200) return true;
97+
// [#23367, ruling A] A revoked key is refused with its own located code,
98+
// `403 API_KEY_REVOKED` — the credential recognised and its state refusing
99+
// it. Any OTHER 403 would mean the key WAS accepted and something later
100+
// refused — a different fact entirely — so the code decides, not the
101+
// status. An unrecognised key keeps the generic 401.
102+
if (res.status === 403) {
80103
const body: any = await res.json();
81-
expect(body?.data?.id).toBeTruthy();
82-
expect(body?.data?.key).toBeTruthy();
83-
return { id: String(body.data.id), raw: String(body.data.key) };
84-
};
85-
86-
/**
87-
* Does this key still authenticate? Asked through a real read with NO bearer
88-
* token, so the key is the only credential present. `showcase_task` is the
89-
* card's own probe and is readable by a member via `showcase_member_default`
90-
* — deliberately NOT `sys_api_key`, so a permission change on the object
91-
* under test can never be mistaken for a credential verdict.
92-
*/
93-
const keyStillAuthenticates = async (raw: string): Promise<boolean> => {
94-
const res = await stack.api('/data/showcase_task?$top=1', { headers: { 'x-api-key': raw } });
95-
if (res.status === 200) return true;
96-
// [#23367, ruling A] A revoked key is refused with its own located code,
97-
// `403 API_KEY_REVOKED` — the credential recognised and its state refusing
98-
// it. Any OTHER 403 would mean the key WAS accepted and something later
99-
// refused — a different fact entirely — so the code decides, not the
100-
// status. An unrecognised key keeps the generic 401.
101-
if (res.status === 403) {
102-
const body: any = await res.json();
103-
expect(body?.error?.code, 'a 403 on the key probe must be the key\'s own revocation').toBe('API_KEY_REVOKED');
104-
return false;
105-
}
106-
expect(res.status, `revoked-key probe should be 401 or 403 API_KEY_REVOKED, got ${res.status}`).toBe(401);
104+
expect(body?.error?.code, 'a 403 on the key probe must be the key\'s own revocation').toBe('API_KEY_REVOKED');
107105
return false;
108-
};
109-
110-
/** Read a key row back with the caller's own credentials. */
111-
const readKey = async (token: string, id: string) => {
112-
const res = await stack.apiAs(token, 'GET', `/data/sys_api_key/${id}`);
113-
const body: any = res.status === 200 ? await res.json() : {};
114-
return { status: res.status, row: body.record ?? body.data ?? {} };
115-
};
116-
117-
beforeAll(async () => {
118-
stack = await bootShowcase({});
119-
adminToken = await stack.signIn();
120-
memberToken = await stack.signUp(MEMBER_EMAIL);
121-
}, 180_000);
122-
123-
afterAll(async () => { await stack?.stop?.(); });
106+
}
107+
expect(res.status, `revoked-key probe should be 401 or 403 API_KEY_REVOKED, got ${res.status}`).toBe(401);
108+
return false;
109+
};
110+
111+
/** Read a key row back with the caller's own credentials. */
112+
const readKey = async (token: string, id: string) => {
113+
const res = await stack.apiAs(token, 'GET', `/data/sys_api_key/${id}`);
114+
const body: any = res.status === 200 ? await res.json() : {};
115+
return { status: res.status, row: body.record ?? body.data ?? {} };
116+
};
117+
118+
beforeAll(async () => {
119+
stack = await bootShowcase({});
120+
adminToken = await stack.signIn();
121+
memberToken = await stack.signUp(MEMBER_EMAIL);
122+
}, 180_000);
123+
124+
afterAll(async () => { await stack?.stop?.(); });
124125

126+
describe('#8053: a member revokes their OWN sys_api_key', () => {
125127
// ── the fixture's own preconditions ───────────────────────────────────────
126128

127129
it('[persona] the principal is an ordinary member resolving the platform baseline', async () => {
@@ -310,3 +312,38 @@ describe('#8053: a member revokes their OWN sys_api_key', () => {
310312
expect((await deleted.json()).code).toBe('OBJECT_API_METHOD_NOT_ALLOWED');
311313
});
312314
});
315+
316+
describe('[objectstack-ai/cloud#3820, card 2] a platform administrator suspends a member\'s key, and only an administrator resumes it', () => {
317+
it('⭐ the administrator\'s revoke refuses the key on its next call; the member\'s restore is refused 403; the administrator\'s restore brings the same key back', async () => {
318+
const { id, raw } = await mintKey(memberToken, 'agent-key');
319+
expect(await keyStillAuthenticates(raw), 'precondition: the member\'s key works').toBe(true);
320+
321+
// The exact request the `revoke_api_key` row action declares, as the administrator.
322+
const revoked = await stack.apiAs(adminToken, 'PATCH', `/data/sys_api_key/${id}`, { revoked: true });
323+
expect(revoked.status, await revoked.clone().text()).toBe(200);
324+
expect(await keyStillAuthenticates(raw), 'refused on its very next call').toBe(false);
325+
expect((await readKey(adminToken, id)).row).toMatchObject({ revoked: true, revoked_reason: 'administrator_suspended' });
326+
327+
// The exact request `restore_api_key` declares, as the member: refused, and nothing moves.
328+
const memberRestore = await stack.apiAs(memberToken, 'PATCH', `/data/sys_api_key/${id}`, { revoked: false });
329+
const memberText = await memberRestore.text();
330+
expect(memberRestore.status, memberText).toBe(403);
331+
expect(JSON.parse(memberText).code ?? JSON.parse(memberText).error?.code).toBe('PERMISSION_DENIED');
332+
expect(memberText).toContain('suspended by a platform administrator');
333+
expect(await keyStillAuthenticates(raw)).toBe(false);
334+
335+
const adminRestore = await stack.apiAs(adminToken, 'PATCH', `/data/sys_api_key/${id}`, { revoked: false });
336+
expect(adminRestore.status, await adminRestore.clone().text()).toBe(200);
337+
expect((await readKey(adminToken, id)).row).toMatchObject({ revoked: false });
338+
expect((await readKey(adminToken, id)).row.revoked_reason ?? null, 'the reason clears on the restore').toBeNull();
339+
expect(await keyStillAuthenticates(raw), 'resumed: the same key works with no re-issue').toBe(true);
340+
});
341+
342+
it('CONTROL: the member\'s own revoke records no reason, and the member restores it as before', async () => {
343+
const { id, raw } = await mintKey(memberToken, 'own-key');
344+
expect((await stack.apiAs(memberToken, 'PATCH', `/data/sys_api_key/${id}`, { revoked: true })).status).toBe(200);
345+
expect((await readKey(memberToken, id)).row.revoked_reason ?? null).toBeNull();
346+
expect((await stack.apiAs(memberToken, 'PATCH', `/data/sys_api_key/${id}`, { revoked: false })).status).toBe(200);
347+
expect(await keyStillAuthenticates(raw)).toBe(true);
348+
});
349+
});

0 commit comments

Comments
 (0)