-
Notifications
You must be signed in to change notification settings - Fork 131
chore(guard): move token routing out off inner router for path-based routing #3279
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
chore(guard): move token routing out off inner router for path-based routing #3279
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
More templates
@rivetkit/actor
@rivetkit/cloudflare-workers
@rivetkit/core
@rivetkit/db
@rivetkit/framework-base
@rivetkit/next-js
@rivetkit/react
rivetkit
@rivetkit/sql-loader
@rivetkit/engine-runner
@rivetkit/engine-runner-protocol
commit: |
Code ReviewOverviewThis PR refactors token routing in the guard package by moving token extraction logic out of the inner routing function to enable proper path-based routing. The changes improve the architecture by handling tokens at the routing layer where they belong. Positive Aspects
Issues and Concerns1. Token Parameter UnusedThe _token parameter is prefixed with underscore indicating it is intentionally unused. While the comment indicates validation happens in the EE edition, ensure EE implementation properly validates tokens to prevent unauthorized access. 2. Typo in Header Constant NameX_RIVET_AMESPACE should be X_RIVET_NAMESPACE (missing N). This constant exists in the current code but should be fixed in a follow-up PR. 3. Error Message Could Be More AccurateLine 102 uses error message invalid x-rivet-actor header but in the route_request_path_based code path, the actor ID comes from the URL path. Consider using a more generic message like invalid actor id format. 4. Typo in Log MessageLine 195: beocme should be become. This exists in the current code but noticed during review. 5. Missing Test CoverageNo unit tests found for the routing logic. Add tests for token extraction, error cases, and path-based routing scenarios. 6. Potential Edge Case: Empty TokenIf a client sends rivet_token. with empty token after the dot, this will successfully extract an empty string. Consider validating that the token is not empty when present. Performance ConsiderationsThe changes have minimal performance impact. The protocols.split operation creates a small temporary allocation, but this is acceptable given WebSocket upgrade requests are infrequent. Security ConsiderationsThe code properly uses to_str() which will fail on invalid UTF-8, preventing header injection attacks. Ensure EE implementation validates tokens properly. Code QualityFollows repository conventions with proper error handling, structured logging, and consistent code style. Recommendations SummaryShould Fix in Follow-up PRs:
ConclusionThis is a solid refactoring that improves the architecture. The code is well-structured and follows the repository conventions. The main concerns are around test coverage and a few minor issues that can be addressed in follow-up PRs. Approved with minor suggestions. |
e7c0c67 to
0c63817
Compare
cc21086 to
727eeb1
Compare
PR Review: Move token routing out of inner router for path-based routingSummaryThis PR refactors token extraction logic to support both header-based and WebSocket protocol-based routing for actor requests. The main change moves token parsing to the outer routing layer ( Code Quality & Best PracticesPositive Changes✅ Consistent token extraction: Token is now extracted consistently in both path-based and header-based routing flows Issues & Concerns1. Premature allocation in WebSocket protocol parsing (pegboard_gateway.rs:60)let protocols: Vec<&str> = protocols_header.split(',').map(|p| p.trim()).collect();This allocates a let mut protocols = protocols_header.split(',').map(|p| p.trim());
let actor_id = protocols
.find_map(|p| p.strip_prefix(WS_PROTOCOL_ACTOR))
.ok_or_else(|| ...)?;
let token = protocols_header
.split(',')
.map(|p| p.trim())
.find_map(|p| p.strip_prefix(WS_PROTOCOL_TOKEN));Or if you need to iterate multiple times, reuse the split operation. 2. Inconsistent error handling for token parsingFor actor ID extraction, you return detailed errors when the header is invalid (lines 83, 94), but for token extraction, you only propagate the context without a custom error. Consider consistency:
Given that token is optional, the current approach might be correct, but it's worth clarifying the intent. 3. Dead code / unused parameter (pegboard_gateway.rs:111)The
Security ConcernsMedium Priority
Recommendation:
Performance Considerations✅ No significant performance impact: The changes are minimal and don't introduce performance regressions Test Coverage
Recommendations:
Additional Observations
Recommendations SummaryMust address:
Should address:
Nice to have:
VerdictThe code changes are functionally sound and follow project conventions, but would benefit from addressing the security concerns around path-based tokens and adding comprehensive test coverage before merging. |
PR Review: Move token routing out of inner router for path-based routingSummaryThis PR refactors token handling in the guard routing logic, moving token extraction to the outer routing layer to support path-based routing patterns. The changes enable tokens to be passed through both WebSocket protocols and HTTP headers to the inner routing logic. Code Quality ✅Positive aspects:
Areas for improvement:
Potential Bugs 🟡WebSocket protocol parsing:
Token parameter now always passed but unused:
Performance Considerations ✅No significant performance concerns:
Security Concerns 🟡
Test Coverage ✅Excellent test coverage for path parsing:
Missing test coverage:
Style & Conventions ✅The code follows the repository's conventions well:
Recommendations
Overall AssessmentThis is a solid refactoring that improves code organization and enables path-based token routing. The main concern is the duplicate constant definition, which should be cleaned up. The security implications depend on the EE implementation, which should be verified separately. Recommendation: Approve with minor cleanup (remove duplicate constant) 🤖 Generated with Claude Code |

No description provided.