-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Add support for allowedHostnames in StrictHttpFirewall #7158
Conversation
are changes needed in |
Any update on this change? Our latest release is being flagged due to this issue now showing up on SourceClear. https://www.sourceclear.com/vulnerability-database/security/incorrect-headers-handling/java/sid-20558. |
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.
Thanks for the PR, @eddumelendez! I've left one feedback item inline.
Also, in answer to your question, yes, DummyRequest
will require an update, otherwise DefaultFilterChainValidator
will throw an exception. Since there is no way to give DummyRequest
the server name, though, it would need to return null
.
This would necessitate StrictHttpFirewall
doing a null check before calling the predicate, otherwise an application would have to quite surprisingly check for a null server name in their predicate. Since getServerName
isn't nullable in the ServletRequest
contract, this isn't ideal, but I don't see another way. Perhaps @rwinch has some ideas.
web/src/main/java/org/springframework/security/web/firewall/StrictHttpFirewall.java
Show resolved
Hide resolved
thanks for the feedback @jzheaux. Changes has been submitted |
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.
Thanks for the updates, @eddumelendez! Please see my feedback inline.
web/src/main/java/org/springframework/security/web/firewall/StrictHttpFirewall.java
Outdated
Show resolved
Hide resolved
web/src/main/java/org/springframework/security/web/firewall/StrictHttpFirewall.java
Outdated
Show resolved
Hide resolved
web/src/main/java/org/springframework/security/web/firewall/StrictHttpFirewall.java
Outdated
Show resolved
Hide resolved
fixed :) |
Thanks again, @eddumelendez! In preparation for merging, would you go ahead and squash your commits? |
Introduce a new method `setAllowedHostnames` which perform the validation against untrusted hostnames. Fixes spring-projectsgh-4310
@jzheaux done :) |
Nice work, @eddumelendez, this is now merged into |
@jzheaux , @eddumelendez , thanks for fixing that. I see the 5.x series release is created. Can we hope it will also be released in 4.x soon? How about 3.x? |
@avodonosov There aren't plans to backport this since it introduces a public API, Note, though, that adding the functionality yourself is quite simple as the void configure(WebSecurity web) {
web
.httpFirewall(new MyCustomFirewall());
} |
@jzheaux , why introducing a public API prevents backporting? (If it was breaking public API then I understood). Thanks for the reply though. Yes, it's possible to implement the same whitelist solution ourselves. |
I'm glad to hear that. Let me know if you run into any trouble.
Spring Security follows semantic versioning. One of the key points is number 7 (emphasis mine):
We've made rare exceptions to this in the past, but this doesn't appear to be one of those. What it means is that the public API doesn't get added to except in minor version releases, e.g. 5.2, 5.3, etc. If there were a known vulnerability related to the Host header, it might be fixed in a different way from this general solution, so it's not really sensible to backport the whitelisting feature on those grounds. |
@jzheaux, I'd like to share 2 things about semantic versioning:
In order to allow several versions of your library in an application, give them different artifact name (spring-security3, spring-security4, spring-security5) and different package names (org.springframework.security3, org.springframework.security4, org.springframework.security5). commons-collections, commons-lang use this approach In short - the principle of immutability applied to versioning, dependency management and backward compatibility. Here immutability of values (APIs) assigned to names (class / artifact names). If version 5 is incompatible with version 4, they should not share fully-qualified class names and artifact names. |
You are correct that this change could be made in a hypothetical 4.3.x, though no such release is planned. I'm not certain what you are driving at with the rest of your comments, but if you'd like to pursue them further, I'd recommend you create a separate ticket as it feels like we are getting off-topic here. The decision to follow semantic versioning is a Spring-wide one, though, so if you are trying to make a case against it, you'd need to make it first with Spring Framework. |
Well, I have this point about semver for years, so the mention just triggered me to present it. There is a valid thinking behind it, but it should be applied with understanding. Simultaneous loading of several versions is crucial. Javascript allows this for free - js packages (in all major package management solutions) do not have a global namespace to interfere (as Java's fully-qualified class names). Js semver doesn't translate to Java so directly and mechanically as people think. For Java the apache common's approach is the best. It's not against semver. It just takes it further, to the point it works. The approach I advocate fully complies to the semver (a subclass, so to speak) - if application refers a dependency, the application receives what it expects in any future evolution made according to the rules. Sorry I'm continuing the offtopic. Also, I'm not ready to push the whole Spring project - I'm afraid it will require more energy than I have and I'm not sure of success with whatever energy. But I decided to mentions it as you referred semver. |
Introduce a new method
setAllowedHostnames
which perform the validationagainst untrusted hostnames.
Fixes gh-4310