feat: single authentication per connection - #7166
Conversation
WalkthroughAuthLayer now caches JWT token verification and permission claims at connection setup instead of per-request. New helpers ChangesJWT Authentication Caching
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/rpc/auth_layer.rs (2)
179-183:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winNormalize the
Bearerscheme before stripping it.
trim_start_matches("Bearer ")only accepts the title-case form, but the HTTP auth scheme is case-insensitive. A client that sendsauthorization: bearer <token>will be rejected here, and thatInvalidRequestthen gets cached for the whole connection.Suggested fix
- let token = token - .to_str() - .map_err(|_| ErrorCode::ParseError)? - .trim_start_matches("Bearer "); + let token = token.to_str().map_err(|_| ErrorCode::ParseError)?; + let token = match token.split_once(' ') { + Some((scheme, value)) if scheme.eq_ignore_ascii_case("Bearer") => value, + _ => token, + };🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/rpc/auth_layer.rs` around lines 179 - 183, The code currently strips the "Bearer " prefix with trim_start_matches("Bearer ") which fails for case variants; update the token parsing so you first convert the header string (from token.to_str()) into an &str and then perform a case-insensitive check for the "bearer " scheme (e.g., using eq_ignore_ascii_case on the prefix or compare a lowercase slice) before slicing it off and returning the token; modify the chain around token.to_str() → .trim_start_matches to do a case-insensitive prefix check and only strip the first 7 bytes when the scheme matches, otherwise return the appropriate ParseError/InvalidRequest path.
184-184:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDo not log bearer tokens.
This writes a replayable credential to logs. With the new per-connection flow, every authenticated WebSocket session will leak its JWT whenever debug logging is enabled.
Suggested fix
- debug!("JWT from HTTP Header: {}", token); + debug!("JWT received from HTTP header");🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/rpc/auth_layer.rs` at line 184, Remove the debug log that prints the raw JWT value ("JWT from HTTP Header: {}") and replace it with a non-sensitive message — e.g. log that a JWT was received or log only non-secret metadata such as its presence or length. Locate the debug! call that references the token variable (the "JWT from HTTP Header" log) in the auth layer and update it to avoid emitting the token itself (do not print token, claims, or any replayable credential).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/rpc/auth_layer.rs`:
- Around line 179-183: The code currently strips the "Bearer " prefix with
trim_start_matches("Bearer ") which fails for case variants; update the token
parsing so you first convert the header string (from token.to_str()) into an
&str and then perform a case-insensitive check for the "bearer " scheme (e.g.,
using eq_ignore_ascii_case on the prefix or compare a lowercase slice) before
slicing it off and returning the token; modify the chain around token.to_str() →
.trim_start_matches to do a case-insensitive prefix check and only strip the
first 7 bytes when the scheme matches, otherwise return the appropriate
ParseError/InvalidRequest path.
- Line 184: Remove the debug log that prints the raw JWT value ("JWT from HTTP
Header: {}") and replace it with a non-sensitive message — e.g. log that a JWT
was received or log only non-secret metadata such as its presence or length.
Locate the debug! call that references the token variable (the "JWT from HTTP
Header" log) in the auth layer and update it to avoid emitting the token itself
(do not print token, claims, or any replayable credential).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 178dc99a-32c8-404e-9548-d9bb72b7f859
📒 Files selected for processing (2)
CHANGELOG.mdsrc/rpc/auth_layer.rs
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
filecoin-project/lotus(manual)
Summary of changes
Changes introduced in this pull request:
Reference issue to close (if applicable)
Closes #7164
Other information and links
Change checklist
Outside contributions
Summary by CodeRabbit