perf(gateway): verify each request's account token once - #261
Conversation
Account-token verification runs PBKDF2 (120,000 iterations, about 17 ms of CPU) inside OperatorAccountService's global lock and then rewrites the accounts file. The role checks added in this branch meant that /v1/*, /apps/chat, A2A, /ws, /ws/live, and mutating MCP tools verified the same token twice per request, halving account-token throughput on those surfaces. Cache the verification outcome in HttpContext.Items for the rest of the request. Revocation, disabling, and role changes still apply from the next request. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughBoth account-token authorization paths now use request-scoped caching for verification results and identities. Tests cover repeated checks within one request and rejection of a revoked token in a subsequent request. ChangesAccount-token authentication
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to No actionable merge-blocking issue is established. The account-token cache is scoped to the request and matching token. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to A token revoked or an account downgraded between checks can still pass a later check in the same request. A new request checks account state again. The added exposure is narrow but affects an authorization boundary. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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 |
Description
Follow-up to #256. This commit was pushed to #256's branch after it had already merged, so it never reached
main.With #256, each gated request verifies the caller's credential twice: once to authenticate (
IsAuthorizedRequest) and again to resolve the role (AuthorizeOperatorRequest). For account tokens, each verification:OperatorAccountService's global lock while it does;That halves account-token throughput on
/v1/*,/apps/chat, A2A,/ws, and the mutating MCP tools, and it doubles the lock time every other request waits behind.Summary
HttpContext.Items. Later checks in the same request reuse it when the presented token matches.Type of Change
Validation
dotnet build OpenClaw.Net.slnx --configuration Release: 0 warnings, 0 errorsdotnet test OpenClaw.Net.slnx --configuration Release --no-build: all passing (run on the branch stacked above this commit; the commit itself is unchanged)dotnet run --project samples/OpenClaw.HelloAgent -c Release --no-buildAccountToken_WhenCheckedTwiceInOneRequest_ShouldBeVerifiedOncefailed before the change. It revokes the token between the two checks, so a second verification is observable.AccountToken_WhenRevokedBeforeNextRequest_ShouldBeRejectedguards against the result leaking across requests.Review Notes
HttpContext.Items)Commercial or Customer-Driven Contribution Disclosure
Same origin as #256. Vendor-neutral gateway performance fix.
Checklist
dotnet test)🤖 Generated with Claude Code
Summary by CodeRabbit