-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add introspect (can hopefully be used for NGINX) #174
base: main
Are you sure you want to change the base?
Conversation
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 PR is looking okay, but there is a minor security issue: I think any client could try to fish for valid tokens for other clients (see the respective comment).
Can you:
- Add a test confirming whether this is possible
- Add a check whether the session belongs to the client doing the introspection
Additionally, we might want to consider making this route optional through the configuration. I wonder, in which scenario is this used? Do you think this is a common requirement?
Client::find_and_authenticate(auth.0.to_string(), &auth.1, &db).await?; | ||
|
||
let IntrospectFormData { token, .. } = form.into_inner(); | ||
let maybe_session = Session::find_by_key(token, &db).await; | ||
Ok(Json(IntrospectResp { | ||
active: maybe_session.is_ok(), | ||
})) |
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.
I think this is missing the following check required by the RFC:
o If the token can be used only at certain resource servers, the
authorization server MUST determine whether or not the token can
be used at the resource server making the introspection call.
With the current code, any client could try to fish for valid tokens.
The other checks required are checked by the Session::find_by_key
function (token is not expired, not invalidated, ...).
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 catch! I'll look at it at a later time, I don't think this pr is high prio
response.into_string().await.expect("response body"); | ||
let data: Value = | ||
serde_json::from_str(&response_body).expect("response json values"); | ||
assert_eq!(data["active"], false); |
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.
assert_eq!(data["active"], false); | |
assert_eq!(data["active"], false, "introspect with invalid token should not be active"); |
response.into_string().await.expect("response body"); | ||
let data: Value = | ||
serde_json::from_str(&response_body).expect("response json values"); | ||
assert_eq!(data["active"], true); |
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.
assert_eq!(data["active"], true); | |
assert_eq!(data["active"], true, "introspect with valid token should be active"); |
|
||
http_client.post("/logout").dispatch().await; | ||
|
||
let form_body = format!("token=1234"); |
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.
let form_body = format!("token=1234"); | |
let form_body = format!("token={}", token); |
I think you meant to test if the token is invalidated?
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.
yes and the test fails 😢
response.into_string().await.expect("response body"); | ||
let data: Value = | ||
serde_json::from_str(&response_body).expect("response json values"); | ||
assert_eq!(data["active"], false); |
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.
assert_eq!(data["active"], false); | |
assert_eq!(data["active"], false, "introspection on invalidated token should return false"); |
Standard: https://datatracker.ietf.org/doc/html/rfc7662#page-4
Hopefully works with https://www.nginx.com/blog/validating-oauth-2-0-access-tokens-nginx/