Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ajuvercr
Copy link
Contributor

Copy link
Collaborator

@rien rien left a 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?

Comment on lines +341 to +347
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(),
}))
Copy link
Collaborator

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, ...).

Copy link
Contributor Author

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let form_body = format!("token=1234");
let form_body = format!("token={}", token);

I think you meant to test if the token is invalidated?

Copy link
Contributor Author

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert_eq!(data["active"], false);
assert_eq!(data["active"], false, "introspection on invalidated token should return false");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants