chore(api-key): remove legacy scan+decrypt auth fallback#4876
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryHigh Risk Overview Removed Operational note: keys without a populated Reviewed by Cursor Bugbot for commit e4ed38a. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThis PR removes the legacy full-scan+decrypt fallback from
Confidence Score: 5/5Safe to merge once the key_hash backfill in production is confirmed complete and the legacy warn log count is at zero — both conditions the PR author calls out explicitly. The inlined logic is a direct lift of the previously tested fast path, no behavioral changes are introduced, all callers already used authenticateApiKeyFromHeader, and the deleted authenticateApiKey export has no remaining references in the codebase. No files require special attention; all four changed files are straightforward deletions of dead code and their corresponding tests. Important Files Changed
Sequence DiagramsequenceDiagram
participant C as Caller
participant S as authenticateApiKeyFromHeader
participant DB as Database
participant P as Permission Utils
C->>S: apiKeyHeader, options
alt no header
S-->>C: "{success:false, error:"API key required"}"
end
alt options.workspaceId set
S->>DB: getWorkspaceBillingSettings(workspaceId)
DB-->>S: workspaceSettings (null → "Workspace not found")
end
S->>S: "keyHash = sha256(apiKeyHeader)"
S->>DB: "SELECT WHERE key_hash = keyHash"
DB-->>S: rows[]
alt rows empty
S-->>C: INVALID
end
S->>S: scope checks (userId, keyType, expiry, workspaceId)
alt scope check fails
S-->>C: INVALID
end
alt workspaceId + personal key
S->>P: getUserEntityPermissions(userId, workspace, workspaceId)
P-->>S: permission (null → INVALID)
end
S-->>C: "{success:true, userId, keyId, keyType, workspaceId}"
Reviews (1): Last reviewed commit: "chore(api-key): remove legacy scan+decry..." | Re-trigger Greptile |
Summary
authenticateApiKeyByHashhelper intoauthenticateApiKeyFromHeader; a hash miss now returns invalid directlyauthenticateApiKeydecrypt-and-compare function and itssafeComparedependencyNote
Keys whose
key_hashcolumn was never backfilled will now fail auth. Safe only if the backfill is complete and the fallback'sAPI key matched via fallback decrypt loopwarn count was zero in prod.Type of Change
Testing
Tested manually —
bunx vitest run lib/api-key/(46 tests pass),bun run lint, andbun run check:api-validation:strictall pass.Checklist