-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
iPhone Xʀ requests blocked by StrictHttpFirewall #9037
Comments
Hi, @qeepcologne, sorry to hear that you're having trouble. I've locally added Are you able to provide a minimal sample that reproduces the issue? In the meantime, you can relax the check by supplying a predicate to @Bean
public HttpFirewall firewall() {
StrictHttpFirewall firewall = new StrictHttpFirewall();
firewall.setAllowedHeaderValues(value -> true); // any header value is acceptable
} Thanks for pointing out the docs. I've added a ticket to document that new feature. |
Hi jzheaux, thanks for the quick response. You are right, i tried to reproduce it via testcase like you and and it worked. I turned off the header value validation as you suggested and we can live with that if it is documented. In our case (app) we can filter the useragent on the client side, but there are also web requests. If there are more people with that issue, we need some exception for the UserAgent Header, otherwise everybody has to turn it off completely, which is not the purpose of the feature. |
Before going down the route of adding a
It could be. A character encoding mismatch seems likely. The URL encoding for ʀ is |
There should be no encoding mismatch, as far as i know only ISO-8859-1 characters are allowed in http headers. |
Correct, the mismatch is something like Apple is expecting the header to be read as UTF-8, but Tomcat, for example, reads it as ISO-8859-1. A quick test of MockHttpServletRequest request = new MockHttpServletRequest();
HttpFirewall firewall = new StrictHttpFirewall();
request.addHeader("r", new String("ʀ".getBytes(), ISO_8859_1));
firewall.getFirewalledRequest(this.request).getHeader("r"); // throws exception I'm not sure if your application server can be configured to read headers as UTF-8, but that's the next place I would look. |
An improved workaround is to parse the header values as UTF-8, like so: @Bean
public HttpFirewall httpFirewall() {
StrictHttpFirewall firewall = new StrictHttpFirewall();
Pattern allowed = Pattern.compile("[\\p{IsAssigned}&&[^\\p{IsControl}]]*");
firewall.setAllowedHeaderValues((header) -> {
String parsed = new String(header.getBytes(ISO_8859_1), UTF_8);
return allowed.matcher(parsed).matches();
});
} I believe this is an improvement since this way |
Thanks, This is Helpful :) |
Hello, I encountered the same problem, but I do not know how to make the above code take effect in my Java application; |
@mxossadm, thanks for reaching out. To keep GitHub focused on issues, please consider posting your question on StackOverflow instead. You are welcome to post a link to your question on this issue if you like so that others can find it and respond. |
Describe the bug
iphone XR cannot connect via websocket, because useragent contains special characters:
iOS 13.7.0 Alamofire/5.2.2 iPhone Xʀ
I think this change caused the problem:
#8644
To Reproduce
websocket connect with user agent above. The problem is all clients that i tested cannot send illegal characters, e.g.
wscat -c wss://staging.qeep.net/restapi/ws --header "User-Agent:iPhone Xʀ"
only apple can send this mess.
Expected behavior
let the requests pass or add clear warning about the change and how to get back the old behaviour
After downgrade to 5.3.4 requests are working, so definitive cause by 5.4.0
The text was updated successfully, but these errors were encountered: