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

Issue #11014 - Cleanup of relative redirect handling Jetty-12 #11019

Merged
merged 9 commits into from
Dec 6, 2023

Conversation

gregw
Copy link
Contributor

@gregw gregw commented Dec 4, 2023

  • Handle request relative redirects
  • Moved to Response
  • Changed default to allow relative

Fixes #11014

+ Handle request relative redirects
+ Moved to Response
+ Changed default to allow relative
+ Handle request relative redirects
+ Moved to Response
+ Changed default to allow relative
@gregw gregw changed the title Cleanup of relative redirect handling #11014 Cleanup of relative redirect handling Jetty-12 #11014 Dec 4, 2023
+ Handle request relative redirects
+ Moved to Response
+ Changed default to allow relative
+ Handle request relative redirects
+ Moved to Response
+ Changed default to allow relative
@joakime joakime changed the title Cleanup of relative redirect handling Jetty-12 #11014 Issue ##11014 - Cleanup of relative redirect handling Jetty-12 Dec 4, 2023
@gregw gregw changed the title Issue ##11014 - Cleanup of relative redirect handling Jetty-12 Cleanup of relative redirect handling Jetty-12. #11014 Dec 4, 2023
+ Handle request relative redirects
+ Moved to Response
+ Changed default to allow relative
+ Handle request relative redirects
+ Moved to Response
+ Changed default to allow relative
@joakime joakime changed the title Cleanup of relative redirect handling Jetty-12. #11014 Issue #11014 - Cleanup of relative redirect handling Jetty-12 Dec 4, 2023
@joakime joakime added this to the 12.0.x milestone Dec 4, 2023
@gregw
Copy link
Contributor Author

gregw commented Dec 5, 2023

@sbordet @joakime @lorban nudge!

@@ -76,7 +76,7 @@ public class HttpConfiguration implements Dumpable
private CookieCompliance _requestCookieCompliance = CookieCompliance.RFC6265;
private CookieCompliance _responseCookieCompliance = CookieCompliance.RFC6265;
private boolean _notifyRemoteAsyncErrors = true;
private boolean _relativeRedirectAllowed;
private boolean _relativeRedirectAllowed = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

(for other reviewers) This changes the default to always use relative redirects (path only).
Prior versions of Jetty would try to always use absolute URIs.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't mind the default behavior change, but maybe it should be justified with a comment?

joakime
joakime previously approved these changes Dec 5, 2023
Comment on lines +615 to +618
@Deprecated
static String toRedirectURI(Request request, String location)
{
if (!URIUtil.hasScheme(location) && !request.getConnectionMetaData().getHttpConfiguration().isRelativeRedirectAllowed())
{
StringBuilder url = new StringBuilder(128);
HttpURI uri = request.getHttpURI();
URIUtil.appendSchemeHostPort(url, uri.getScheme(), Request.getServerName(request), Request.getServerPort(request));

if (location.startsWith("/"))
{
// absolute in context
location = URIUtil.normalizePathQuery(location);
}
else
{
// relative to request
String path = uri.getPath();
String parent = (path.endsWith("/")) ? path : URIUtil.parentPath(path);
location = URIUtil.normalizePathQuery(URIUtil.addEncodedPaths(parent, location));
if (location != null && !location.startsWith("/"))
url.append('/');
}

if (location == null)
throw new IllegalStateException("redirect path cannot be above root");
url.append(location);

location = url.toString();
}
// TODO do we need to do request relative without scheme?

return location;
return Response.toRedirectURI(request, location);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would have left the original code, and not moved it to Response.
The response is never used in the implementation, and enforces that in order to build a redirect URI, you need a Request (not a Response).

Copy link
Contributor Author

@gregw gregw Dec 6, 2023

Choose a reason for hiding this comment

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

@sbordet, Sending a redirect is a response function and it naturally lives next to the sendRedirect methods. Plus we often pass the request and the response into these static methods e.g. Response.sendRedirect(Request, Response, Callback, location)

@gregw gregw requested review from joakime and sbordet December 6, 2023 04:45
@@ -76,7 +76,7 @@ public class HttpConfiguration implements Dumpable
private CookieCompliance _requestCookieCompliance = CookieCompliance.RFC6265;
private CookieCompliance _responseCookieCompliance = CookieCompliance.RFC6265;
private boolean _notifyRemoteAsyncErrors = true;
private boolean _relativeRedirectAllowed;
private boolean _relativeRedirectAllowed = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't mind the default behavior change, but maybe it should be justified with a comment?

@gregw gregw merged commit 7135433 into jetty-12.0.x Dec 6, 2023
8 checks passed
@gregw gregw deleted the fix/jetty-12/11014/relativeRedirect branch December 6, 2023 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

RedirectRegexRule and RewritePatternRule should consider relativeRedirectAllowed
4 participants