-
Notifications
You must be signed in to change notification settings - Fork 2k
Issue #12720 - fix servlet error dispatch for errors generated by SecurityHandler #13693
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
base: jetty-12.1.x
Are you sure you want to change the base?
Issue #12720 - fix servlet error dispatch for errors generated by SecurityHandler #13693
Conversation
…curityHandler Signed-off-by: Lachlan Roberts <lachlan.p.roberts@gmail.com>
Signed-off-by: Lachlan Roberts <lachlan.p.roberts@gmail.com>
|
@lachlan-roberts the CI failures look to be more than flakes. |
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.
more than flakes
|
@gregw the tests are failing because the So do you think i should adjust both the |
Signed-off-by: Lachlan Roberts <lachlan.p.roberts@gmail.com>
Signed-off-by: Lachlan Roberts <lachlan.p.roberts@gmail.com>
jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/SecurityHandler.java
Outdated
Show resolved
Hide resolved
| }; | ||
| } | ||
|
|
||
| return response; |
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 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
| 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; | ||
| } | ||
| }; | ||
| } |
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.
| 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; | |
| } | |
| }; | |
| } |
Closes #12720
Currently
SecurityHandlerdoes onlyResponse.writeErrorwhen a 403 response needs to be sent. However this will not dispatch to a servlet error page, for this we need to doAuthenticationState.writeErrorand handle the case if it returnsAuthenticationState.ServeAs.