-
Notifications
You must be signed in to change notification settings - Fork 6k
Timing for HeaderWriterFilter to writes headers changed in 4.2.5 breaks existing codes. #5193
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
Comments
@tan9 I agree with what you are saying, it definitely seems more obvious to me that the security headers should be set earlier and then the controller should be able to override them. Another issue with it is that the OnCommittedResponseWrapper just doesn't seem to do its job reliably as I posted here - #3975 (comment) |
This does appear to be an issue. I think we need to modify it to check to see if the header is already set and if so not to override it. If anyone is interested in submitting a PR that would help get this issue resolved faster as we are focused on some other tasks at the moment. |
@rwinch thanks for your response, I am willing to contribute. Would you please provide some direction how to do it right. Use another responseWrapper within |
Thanks for the fast response! I think we should just update the HeaderWriter implementations to only write if the value isn't present. |
All HeadersWriter only write Header if its not already written. Fixes: spring-projectsgh-6454 spring-projectsgh-5193
Workarounds are mentioned in #2953. |
Closing this as a duplicate of gh-2953 |
Summary
In Spring Security 4.2.4 or earlier, the HeaderWriterFilter writes headers before filter chin was processed.
However, commit f81b581#diff-57c0f670220b7f4e45a0d1252a99b482 in 4.2.5 changed the timing of header writing to
response.onResponseCommitted
phase. And this will break existing code which writes custom headers other than those defined inHeaderWriter
s. For example:I have some URL intend to be embed in frames. In 4.2.4 or earlier, I can overwrite the default value from
XFrameOptionsHeaderWriter
as following :Now I have no easy way to set
X-Frame-Options
toSAMEORIGIN
in dedicate URLs while applyingDENY
to rest or the system.Call sequence illustrated for above code snippet in 4.2.5.RELEASE:
Resulting
X-Frame-Options=DENY
.Call sequence illustrated for 4.2.4.RELEASE and earlier:
Resulting
X-Frame-Options=SAMEORIGIN
as expected.Actual Behavior
response.setHeader
in controller code will not take effect as before.Expected Behavior
Manual
response.setHeader
in controller code overwrites headers wrote byHeaderWriter
s.Configuration
N/A
Version
4.2.5.RELEASE
Sample
N/A
The text was updated successfully, but these errors were encountered: