Skip to content

Conversation

@lachlan-roberts
Copy link
Contributor

Closes #12720

Currently SecurityHandler does only Response.writeError when a 403 response needs to be sent. However this will not dispatch to a servlet error page, for this we need to do AuthenticationState.writeError and handle the case if it returns AuthenticationState.ServeAs.

…curityHandler

Signed-off-by: Lachlan Roberts <lachlan.p.roberts@gmail.com>
Signed-off-by: Lachlan Roberts <lachlan.p.roberts@gmail.com>
@gregw
Copy link
Contributor

gregw commented Oct 13, 2025

@lachlan-roberts the CI failures look to be more than flakes.

Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

more than flakes

@lachlan-roberts
Copy link
Contributor Author

@gregw the tests are failing because the AuthenticationState.writeError and ErrorHandler.writeError do not support taking a message string.

So do you think i should adjust both the AuthenticationState.writeError and ErrorHandler.writeError API to take a String message, or should I adjust the tests to not check for the !authroized string?

@joakime joakime moved this to 👀 In review in Jetty 12.1.4 Oct 16, 2025
Signed-off-by: Lachlan Roberts <lachlan.p.roberts@gmail.com>
@lachlan-roberts lachlan-roberts requested a review from gregw October 20, 2025 23:33
Signed-off-by: Lachlan Roberts <lachlan.p.roberts@gmail.com>
@lachlan-roberts lachlan-roberts requested a review from gregw October 21, 2025 00:19
};
}

return response;
Copy link
Contributor

Choose a reason for hiding this comment

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

This can return the unwrapped response, which will provide the unwrapped request. So either only wrap the request in the if statement above OR you always need to wrap the response to return the wrapped request. See above suggestion

Comment on lines +600 to +636
HttpURI uri = request.getHttpURI();
Request wrappedRequest = serveAs.wrap(request);
if (!uri.equals(wrappedRequest.getHttpURI()))
{
// URI is replaced, so filter out all metadata for the old URI
response.getHeaders().put(HttpHeader.CACHE_CONTROL.asString(), HttpHeaderValue.NO_CACHE.asString());
response.getHeaders().putDate(HttpHeader.EXPIRES.asString(), 1);
HttpFields.Mutable headers = new HttpFields.Mutable.Wrapper(response.getHeaders())
{
@Override
public HttpField onAddField(HttpField field)
{
if (field.getHeader() == null)
return field;
return switch (field.getHeader())
{
case CACHE_CONTROL, PRAGMA, ETAG, EXPIRES, LAST_MODIFIED, AGE -> null;
default -> field;
};
}
};

return new Response.Wrapper(wrappedRequest, response)
{
@Override
public HttpFields.Mutable getHeaders()
{
return headers;
}

@Override
public Request getRequest()
{
return wrappedRequest;
}
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
HttpURI uri = request.getHttpURI();
Request wrappedRequest = serveAs.wrap(request);
if (!uri.equals(wrappedRequest.getHttpURI()))
{
// URI is replaced, so filter out all metadata for the old URI
response.getHeaders().put(HttpHeader.CACHE_CONTROL.asString(), HttpHeaderValue.NO_CACHE.asString());
response.getHeaders().putDate(HttpHeader.EXPIRES.asString(), 1);
HttpFields.Mutable headers = new HttpFields.Mutable.Wrapper(response.getHeaders())
{
@Override
public HttpField onAddField(HttpField field)
{
if (field.getHeader() == null)
return field;
return switch (field.getHeader())
{
case CACHE_CONTROL, PRAGMA, ETAG, EXPIRES, LAST_MODIFIED, AGE -> null;
default -> field;
};
}
};
return new Response.Wrapper(wrappedRequest, response)
{
@Override
public HttpFields.Mutable getHeaders()
{
return headers;
}
@Override
public Request getRequest()
{
return wrappedRequest;
}
};
}
HttpURI uri = request.getHttpURI();
Request wrappedRequest = serveAs.wrap(request);
HttpFields.Mutable headers;
if (uri.equals(wrappedRequest.getHttpURI()))
{
headers = response.getHeaders()
}
else
{
// URI is replaced, so filter out all metadata for the old URI
response.getHeaders().put(HttpHeader.CACHE_CONTROL.asString(), HttpHeaderValue.NO_CACHE.asString());
response.getHeaders().putDate(HttpHeader.EXPIRES.asString(), 1);
headers = new HttpFields.Mutable.Wrapper(response.getHeaders())
{
@Override
public HttpField onAddField(HttpField field)
{
if (field.getHeader() == null)
return field;
return switch (field.getHeader())
{
case CACHE_CONTROL, PRAGMA, ETAG, EXPIRES, LAST_MODIFIED, AGE -> null;
default -> field;
};
}
};
}
return new Response.Wrapper(wrappedRequest, response)
{
@Override
public HttpFields.Mutable getHeaders()
{
return headers;
}
@Override
public Request getRequest()
{
return wrappedRequest;
}
};
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

Error attributes not set on request in Jetty 12

2 participants