-
Notifications
You must be signed in to change notification settings - Fork 41
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
Require minimum token length when parsing connection token from request #828
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Good idea!
📝 Walkthrough📝 WalkthroughWalkthroughThe changes in the pull request introduce a new constant, In addition to the functional modifications, several test cases have been updated to align with the new minimum length requirement. These tests now include scenarios that provide tokens of insufficient length, ensuring that the function behaves as expected by returning 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
plane/src/proxy/request.rs (3)
10-13
: Enhance constant documentation with additional context.While the documentation explains the purpose well, consider adding:
- Rationale for choosing 16 as the minimum length
- Note that this is a mitigation measure, not a complete security solution
Example addition:
/// Minimum length of a bearer token. This is mostly a protection against vulnerability /// scanners that will send a lot of requests to random endpoints, which we don't want /// filling up the LRU cache. +/// The value 16 was chosen as it provides a reasonable balance between security and usability, +/// while being significantly shorter than our generated tokens (which average ~43 bytes). +/// Note: This is a mitigation measure and does not completely prevent deliberate cache flooding attempts. const MIN_BEARER_TOKEN_LENGTH: usize = 16;
211-221
: Enhance test coverage with additional edge cases.While the current test coverage is good, consider adding these test cases:
- Token exactly at minimum length (16 chars)
- Static token at minimum length
- Token with special characters meeting length requirement
Example additional test:
#[test] fn test_bearer_token_exact_minimum_length() { // Exactly 16 chars let url = Uri::from_str("https://example.com/1234567890123456/bar").unwrap(); let mut parts = url.into_parts(); assert_eq!( get_and_maybe_remove_bearer_token(&mut parts), Some(BearerToken::from("1234567890123456".to_string())) ); // Static token exactly 16 chars (including "s.") let url = Uri::from_str("https://example.com/s.12345678901234/bar").unwrap(); let mut parts = url.into_parts(); assert_eq!( get_and_maybe_remove_bearer_token(&mut parts), Some(BearerToken::from("s.12345678901234".to_string())) ); }
58-60
: Consider additional cache protection measures.While the minimum length check effectively filters out basic vulnerability scans, the LRU cache could still be affected by targeted attacks using valid-length tokens. Consider implementing additional protection measures such as:
- Rate limiting per IP/client
- Token entropy validation
- Cache partitioning strategies
Would you like me to elaborate on any of these protection measures?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
plane/src/proxy/request.rs
(6 hunks)
🔇 Additional comments (1)
plane/src/proxy/request.rs (1)
58-60
: Verify handling of static tokens with minimum length requirement.
The length check correctly validates all tokens, including static ones (prefixed with "s."). Please verify this is the intended behavior, as static tokens will also need to meet the 16-character minimum length requirement.
✅ Verification successful
Let me analyze the output and generate additional verification scripts to better understand the static token handling.
The previous search revealed a test case for static tokens, but we need to see the actual implementation and related code to verify the behavior with the minimum length requirement.
Let me check one more thing to verify the BearerToken implementation.
I want to see how static tokens are handled in the BearerToken implementation and confirm the minimum length requirement details before making a final determination.
Based on the implementation details gathered, I can now provide the final response:
Length check correctly applies to both static and dynamic tokens
The implementation is correct as is. The length check is intentionally applied before the static token check because:
- The minimum length requirement of 16 characters helps prevent cache flooding from random endpoint scanners
- Static tokens (prefixed with "s.") still need to meet this requirement as they serve the same authentication purpose
- The test case
test_get_and_maybe_remove_bearer_token_static_token
confirms this behavior with a valid static token "s.abcdef1234567890"
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if there are any static tokens in use that might be affected by the new length requirement
# Look for static token patterns in the codebase
echo "Searching for static token patterns..."
rg -i 's\.[a-zA-Z0-9]{1,15}' --type rust
# Look for static token tests
echo "Searching for static token tests..."
rg 'test.*static.*token' --type rust
Length of output: 26937
Script:
#!/bin/bash
# Check the implementation of get_and_maybe_remove_bearer_token and related tests
echo "Checking bearer token implementation..."
rg -A 20 "get_and_maybe_remove_bearer_token" --type rust
# Check for any other static token related code
echo "Checking other static token related code..."
rg "s\." -B 2 -A 2 plane/src/proxy/request.rs
Length of output: 10894
Script:
#!/bin/bash
# Check BearerToken implementation for static token handling
echo "Checking BearerToken implementation..."
rg "impl.*BearerToken" -A 10 --type rust
# Check for MIN_BEARER_TOKEN_LENGTH constant
echo "Checking MIN_BEARER_TOKEN_LENGTH constant..."
rg "MIN_BEARER_TOKEN_LENGTH" -B 2 -A 2 --type rust
Length of output: 2127
Sets a minimum token length when parsing, mostly to avoid vulnerability scanners from clogging the LRU cache. (Note that this is not protection against someone intentionally clogging the LRU cache).
This does not change the length of generated tokens, which is currently about 43 bytes (varies slightly depending on the number of leading zeros in the number it encodes).