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

First authorization request produced by OIDC module fails due to inclusion of sessionid #4227

Closed
travisspencer opened this issue Oct 21, 2019 · 2 comments
Assignees

Comments

@travisspencer
Copy link
Contributor

Whenever I access my Relying Party (RP) that is protected by the new OpenID Connect (OIDC) module, I'm immediately redirected to the authorization endpoint of my OpenID Connect Provider (OP). This is perfect and as it should be for my configuration. However, this request contains ;jsessionid=... at the end of the URI. Here's an example:

https://localhost:8443/dev/oauth/authorize;jsessionid=node01as2n4r9s0lby1ixubxa1v8zww2.node0?client_id=jetty%2Dtest&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fj%5Fsecurity%5Fcheck&scope=openid&state=7l6kd92a37la0225rfj5pvedm3&response_type=code

This extra ;jsessionid=... causes 404 in my OP. Repeating the request fixes it. If I clear the session state (cookies, local storage, etc.) by opening a new private browsing session, I ALWAYS get this on the first authorization request. Subsequent requests NEVER include this extra ;jsessionid=... in the URI.

@travisspencer
Copy link
Contributor Author

This is fixed by a small change:

Index: jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdAuthenticator.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdAuthenticator.java	(date 1569810226000)
+++ jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdAuthenticator.java	(date 1571644743691)
@@ -399,7 +399,7 @@
             if (LOG.isDebugEnabled())
                 LOG.debug("challenge {}->{}", session.getId(), challengeUri);
             int redirectCode = (baseRequest.getHttpVersion().getVersion() < HttpVersion.HTTP_1_1.getVersion() ? HttpServletResponse.SC_MOVED_TEMPORARILY : HttpServletResponse.SC_SEE_OTHER);
-            baseResponse.sendRedirect(redirectCode, response.encodeRedirectURL(challengeUri));
+            baseResponse.sendRedirect(redirectCode, challengeUri);
 
             return Authentication.SEND_CONTINUE;
         }

I'm unsure, but thinking that response.encodeRedirectURL(String) is for internal redirects whereas this is an external one. Could that be? Is that change above the one that's needed? Will it break things in a clustered environment? (I didn't test that; only a single-node setup.)

@lachlan-roberts
Copy link
Contributor

This is sending the jsessionid in the URL so it can remember the session if cookies aren't being used.

I tested OpenID with Google and Microsoft and they both do not allow you to authenticate with cookies disabled, and Microsoft gave a 404 response as well for the ;jsessionid=... in the URL.

So yes, I think the best thing to do is remove response.encodeRedirectURL so we don't add this to the redirect URL.

lachlan-roberts added a commit that referenced this issue Oct 22, 2019
lachlan-roberts added a commit that referenced this issue Oct 22, 2019
lachlan-roberts added a commit that referenced this issue Oct 22, 2019
* Issue #4227 - do not use encodeRedirectURL for openid redirects

Signed-off-by: Lachlan Roberts <[email protected]>

* changes from review

Signed-off-by: Lachlan Roberts <[email protected]>
@joakime joakime changed the title 1st authorization request produced by OIDC module fails due to inclusion of sessionid First authorization request produced by OIDC module fails due to inclusion of sessionid Oct 22, 2019
@lachlan-roberts lachlan-roberts self-assigned this Oct 23, 2019
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

No branches or pull requests

2 participants