-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Feat: Auth via ticketing for Websocket #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Claude finished @AshishKumar4's task in 2m 15s —— View job Code Quality & Security Review (Critical Path)Recommendation: APPROVE PR SummaryImplements a ticket-based authentication system for WebSocket connections, enabling SDK clients to authenticate without browser cookies or origin validation. Tickets are one-time-use, short-lived (15s TTL) tokens stored in Durable Object memory. PR Description
Addressed Issues
Code Quality
Details: Medium - No Ticket Limit per DO Low - Deterministic Session ID Fallback Security
Security Strengths:
Token Format Analysis: TestingTo verify:
Tests to add:
Final RecommendationAPPROVE - This is a well-designed authentication system that follows security best practices:
The medium-severity issues noted are acceptable tradeoffs given the mitigations in place. Consider adding the test suite mentioned above in a follow-up PR. |
|
|
||
| switch (resourceType) { | ||
| case 'vault': | ||
| return `${VAULT_TICKET_PREFIX}${resourceId}_${random}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Medium] The vault ticket format tkv_{userId}_{random} embeds the user ID directly in the token. This has some implications:
- URL Logging: If URLs are logged (server logs, CDN logs, browser history), user IDs get exposed
- Information Disclosure: Anyone intercepting the WebSocket URL can extract the user ID
Mitigation factors:
- Short 15s TTL limits exposure window
- Connections should be over TLS
- User IDs are not highly sensitive in this context
Consider: Using an opaque token format (like agent tickets) and looking up the user via the DO where the ticket is stored. However, given the mitigations and complexity tradeoff, this is acceptable for the current use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User ID is anyways not considered a secret, and it's required to verify the token resource ownership
Summary
Implements a ticket-based authentication system for WebSocket connections, enabling SDK clients to authenticate without relying on browser cookies or origin validation.
Changes
worker/middleware/auth/ticketAuth.ts): One-time-use tokens with 15-second TTL for WebSocket authworker/utils/wsTicketManager.ts): In-memory storage with automatic expiry cleanupworker/api/controllers/ticket/controller.ts): POST/api/ws-ticketendpoint for ticket creationworker/middleware/auth/routeAuth.ts): Extended to support dual auth strategies (ticket or JWT)CodeGeneratorAgentandUserSecretsStoreMotivation
SDK clients (non-browser environments) cannot rely on cookie-based authentication or pass origin headers. This ticket system provides:
Testing
POST /api/ws-ticketwith JWT auth?ticket=tk_xxxparameterSecurity Considerations
checkAppOwnershipBreaking Changes
None - existing JWT/cookie authentication continues to work unchanged.