fix(api): default capability tokens to 30-day expiry - #444
Merged
Merged
Conversation
Minted tokens without expires_at previously never expired, turning any leaked delegation token into a permanent grant. Enforce at the shared service boundary for REST and MCP: default 30 days, reject past or beyond-365-day values with INVALID_REQUEST, surface MCP mint errors as tool errors, and document the policy. Closes #434 Co-Authored-By: Duyet Le <me@duyet.net> Co-Authored-By: duyetbot <bot@duyet.net>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Reviewer's GuideCapability-token minting now enforces a shared expiry policy: omitted expiries receive a persisted 30-day TTL, explicit expiries must be future safe Unix-millisecond values within 365 days, and invalid values produce consistent REST or MCP errors before token creation. Sequence diagram for capability-token expiry enforcementsequenceDiagram
participant Client
participant REST_MCP as REST_or_MCP
participant Service as CapabilityTokenService
participant DB
Client->>REST_MCP: Mint capability token
REST_MCP->>Service: createCapabilityToken(db, projectId, input)
alt expires_at omitted
Service->>Service: Apply 30-day expiry
else expires_at provided
Service->>Service: Validate future safe integer within 365 days
alt Invalid expiry
Service-->>REST_MCP: CapabilityTokenExpiryError
REST_MCP-->>Client: INVALID_REQUEST / ToolError
end
end
Service->>DB: Insert token with expiresAt
DB-->>Service: Created row
Service-->>REST_MCP: Token response with expires_at
REST_MCP-->>Client: Mint response
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Co-Authored-By: Duyet Le <me@duyet.net> Co-Authored-By: duyetbot <bot@duyet.net>
The mint API now rejects past expires_at with 400 INVALID_REQUEST, so the edge-case test minting an already-expired token got 400 instead of 201. Mint with a valid future expiry, then force-expire the capability_tokens row directly in D1 before the 401-on-use assertion — same direct-row pattern as insertLease(). Mint-time rejection coverage already exists in v2-capability-tokens-leases.test.ts. Co-Authored-By: Duyet Le <me@duyet.net> Co-Authored-By: duyetbot <bot@duyet.net> Co-Authored-By: Claude Code <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Verified the regression test fails against the old null-expiry behavior.
Closes #434.
Validation
Do not merge: awaiting review per user instruction.
Co-Authored-By: Duyet Le me@duyet.net
Co-Authored-By: duyetbot bot@duyet.net
🤖 Generated with Claude Code
Summary by Sourcery
Enforce bounded expiration for newly minted capability tokens across REST and MCP interfaces.
Bug Fixes:
Enhancements:
Documentation:
Tests: