Skip to content

Enforce operator revocation on cached tokens; refuse conflicting org context - #30

Merged
mekado11 merged 1 commit into
mainfrom
claude/activation-operator-cli
Sep 23, 2026
Merged

mekado11 merged 1 commit into
mainfrom
claude/activation-operator-cli

Conversation

@mekado11

Copy link
Copy Markdown
Owner

Follow-up to #29, addressing the two Codex review findings that arrived as it merged.

P1: revocation didn't reach tokens that were already issued

revoke-operator removed the claim and revoked refresh tokens, but isSuperAdmin() in firestore.rules only checked the claim. An ID token issued earlier therefore kept global Firestore authority for up to an hour. The server APIs were not affected because they already call verifyIdToken(..., true).

  • revoke-operator now also writes operator_revocations/{uid} with revoked_at_seconds taken from Auth's tokensValidAfterTime.
  • isSuperAdmin() rejects a claimed token whose auth_time isn't later than that value, so revocation takes effect immediately. Signing in again after a re-grant works normally.
  • operator_revocations/** is denied to every browser client, including current operators, and is excluded from the legacy admin catch-all rule. Only the Admin SDK writes it.
  • Cost: one exists()/get() on the same document, and only when the super-admin branch is evaluated.

P2: provision-org silently accepted a conflicting context

An existing context-v1 that was retired or had different text was skipped, and the run reported a no-op. It now parses the existing record and refuses with CONTEXT_EXISTS_WITH_DIFFERENT_CONTENT unless it is published with identical text.

Rules deploy note

This changes firestore.rules. It ships with the same reviewed rules deploy in runbook step 5; nothing deploys automatically.

Verification

  • New rules test: a claimed token with auth_time before the revocation is denied reads and writes; a later sign-in is allowed; the revocation document can't be read, written or deleted by any browser client; operators without a revocation record are unaffected.
  • The operator tests now assert the revocation record matches Auth's revocation time, and that a conflicting or retired context is refused.
  • Locally on the Firebase emulators: operator, legacy-rules and security suites 38/38; typecheck:v2; test:v2 68/68; test:security 52/52.

🤖 Generated with Claude Code

https://claude.ai/code/session_017SrzLVR7J3b9nCU177esz8


Generated by Claude Code

…ontexts

revoke-operator revoked refresh tokens, but Firestore rules only checked the
claim, so an already-issued ID token kept global authority for up to an
hour. Revocation now records operator_revocations/{uid} with the Auth
tokens-valid-after time, and isSuperAdmin rejects claimed tokens whose
auth_time precedes it. The revocation root is browser-inaccessible and
excluded from the legacy admin catch-all.

provision-org silently skipped an existing context-v1 even when it was
retired or had different text; it now refuses such conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017SrzLVR7J3b9nCU177esz8
@vercel

vercel Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hubcys Ready Ready Preview Sep 23, 2026 8:33pm UTC

@mekado11
mekado11 merged commit a3bcefa into main Sep 23, 2026
5 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4344acac3f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/v2/operator.ts
Comment on lines +123 to +126
await auth.revokeRefreshTokens(uid);
const validAfter = (await auth.getUser(uid)).tokensValidAfterTime;
const revokedAt = Math.floor(Date.parse(validAfter ?? new Date().toISOString()) / 1000);
await revocationRef.set({ uid: user.uid, revoked_at_seconds: revokedAt, recorded_at: new Date().toISOString(), source: 'operator_cli' });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Persist the revocation marker before relying on Auth changes

If the Firestore write fails after setCustomUserClaims and revokeRefreshTokens succeed—for example during a transient Firestore outage—the command exits with an error but previously issued ID tokens still satisfy isSuperAdmin() because no revocation document exists, preserving global access for up to their remaining lifetime. Make the fail-closed marker durable before the Auth mutations, or otherwise compensate/retry the cross-service operation so a partial failure cannot defeat the immediate-revocation guarantee.

Useful? React with 👍 / 👎.

This branch was successfully deployed

1 active deployment
Preview — 4344acac Deployed Sep 23, 2026 by vercel[bot]
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