-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Faucet] Support ratelimiting on Firebase JWT #15525
Conversation
⏱️ 2h 55m total CI duration on this PR
🚨 1 job on the last run was significantly faster/slower than expected
|
acdbced
to
a653ee4
Compare
headers | ||
.get(X_IS_JWT_HEADER) | ||
.and_then(|v| v.to_str().ok()) | ||
.map(|v| v.eq_ignore_ascii_case("true")) | ||
.ok_or_else(|| { | ||
AptosTapError::new( | ||
format!( | ||
"The {} header must be present and set to 'true'", | ||
X_IS_JWT_HEADER | ||
), | ||
AptosTapErrorCode::AuthTokenInvalid, | ||
) | ||
})?; |
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.
The current code checks for the presence of the x-is-jwt
header but silently accepts any value other than true
. This creates a potential security issue where a header value of false
or any other string would pass validation. Consider replacing the .map()
with .and_then()
to explicitly validate that the header value is true
and return an error for all other values. For example:
.and_then(|v| {
if v.eq_ignore_ascii_case("true") {
Some(())
} else {
None
}
})
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
2abd113
to
c023f20
Compare
c023f20
to
1f99e0d
Compare
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.
lgtm
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ Forge suite
|
✅ Forge suite
|
✅ Forge suite
|
Description
This PR supports configuring the Redis ratelimiter to ratelimit by either IP or JWT.
I asked @geekflyer to transfer the firebase-token fork to aptos-labs, I'll use that once it's done.
How Has This Been Tested?
Run a localnet:
Run Redis:
Run the faucet:
The config looks like this:
See that a request without a JWT gets rejected:
See that a request with a valid JWT passes:
See that it eventually gets ratelimited:
See that using an API key in
/tmp/bypass-auth-tokens.txt
lets me bypass the limit:I also verified that the IP based ratelimiting still works as before.
See also that the integration tests pass:
Key Areas to Review
Ensure the checks make sense, find any security issues, etc.
Type of Change
Which Components or Systems Does This Change Impact?
Checklist