-
Notifications
You must be signed in to change notification settings - Fork 49
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
refactor: Clean up Tokenserver code #1087
Conversation
src/tokenserver/extractors.rs
Outdated
static ref SERVER_LIMITS: Arc<ServerLimits> = Arc::new(ServerLimits::default()); | ||
} | ||
|
||
const RSA_PRIVATE_KEY: &str = "-----BEGIN RSA PRIVATE KEY-----\n\ |
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.
This is a key I generated specifically for the purposes of testing
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.
In this past, our security teams have advised me not to do even this. They suggested generating the keys at test time / somewhere in the repo, instead of checking them in.
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.
Ah, noted - thanks for the tip. I'll go ahead and do that then
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.
Oh, and to expand on my previous message: The reasoning was that if you see an RSA key in a repo, it should set off alarm bells. It's easier to just never set of the alarms, instead of continually noting that it's fine.
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.
Makes sense. And in this case, it literally set off alarm bells (in the form of a GitGuardian email)
|
||
impl TokenserverRequest { | ||
fn get_fxa_uid(jwt: &str, rsa_modulus: String, rsa_exponent: String) -> Result<String, Error> { | ||
decode::<Claims>( |
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.
Stupid question, do we know what happens if we send in a JWT with alg="None"
? That's a fairly common attack vector.
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.
Not a stupid question! It looks like the crate we use doesn't support the None
algorithm, so validation will fail: https://github.com/Keats/jsonwebtoken/blob/2f25cbed0a906e091a278c10eeb6cc1cf30dc24a/src/algorithms.rs#L48-L66
I'll verify this manually to be sure
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.
Confirmed that "alg": "none"
in the JWT headers results in a 400 error
Description
Adds a
tokenserver
module, with functionality split into separate files.Testing
First, you'll need to create a new MySQL database and add the appropriate tables. DDL and SQL to accomplish this can be found in this gist.
I was able to test this by creating a valid JWT (I generated a set of RSA keys to test with) with the
jwt
Python package and sending off a request like so (I used Postman):I tested the following cases:
Issue(s)
Closes #1052, #968