-
Notifications
You must be signed in to change notification settings - Fork 694
Incorrect header in useHttpBasicAuthForPasswordFlow #368
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
Has this been sorted yet |
@joelmuskwe Don't think so. I've created a PR to fix things. If you need it right away I suggest making a custom build (or very maybe a http interceptor might give a workaround?), otherwise will have to wait a bit until a bugfix lands. |
I would also suggest changing header value prefix from 'BASIC ' to 'Basic ' as most frameworks check value using a case-sensitive startsWith method. |
@vogoltsov They do? Which ones? All servers I've worked with are case insensitive I think. Also, IIRC, the RFC specifies that the auth scheme should be treated in a case insensitive manner. If you have an example server (or reference that it should be case sensitive) then it should probably be changed or made configurable. If so, I think creating a seperate issue would be good too? |
Hello, org.springframework.security.web.authentication.www.BasicAuthenticationFilter.java // line:175 Thanks, |
@vinliangx Well, oh my, you're right I see the same in the source for latest release of Spring. I think that might be a bug in Spring though. Looking at RFC 7617 specifically section 2 it's stated that (emphasis mine):
Disclaimer: I'm not great at estimating if I was looking at the right spec/rfc, so someone might correct me on this. On the other hand:
so I'll update my PR accordingly. |
After further discussion and research in manfredsteyer#368 I noticed that even though RFC 7617 seems to state that: > Note that both scheme and parameter names are matched > case-insensitively. All the examples use "Basic" instead of "BASIC". There is one very notable framework that checks case *sensitively* for "Basic". Given that the header was incorrect anyways, we can be sure that changing this casing won't further break anything, and work around issues for server side frameworks like Spring. See: https://tools.ietf.org/html/rfc7617 See: https://github.com/spring-projects/spring-security/blob/5.0.6.RELEASE/web/src/main/java/org/springframework/security/web/authentication/www/BasicAuthenticationFilter.java#L157 Fixes manfredsteyer#368
Note that this code in IdentityServer4 (a notable .NET server side framework) does the |
I read in a few places that should be case insensitive, so the issue may go to Spring Framework, but I figure it would be easier to here. Meanwhile I did a workaround with a filter to modify the request in my service so everything goes smoothly from the web app. I think this change won't cause major issues to anyone. Thanks @jeroenheijmans! |
@vinliangx Nice, good to hear you found a workaround. It might be worth sharing here so others can use it too while the issue remains unfixed. |
This is the workaround I've implemented for Spring Security: The filter import org.springframework.web.filter.OncePerRequestFilter;
@Component
public class BasicAuthHeaderFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response,
FilterChain chain) throws ServletException, IOException {
HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(request) {
@Override
public String getHeader(String name) {
String header = super.getHeader(name);
if (header == null && name.equalsIgnoreCase("authorization")){
header = super.getHeader("authentication");
}
if (header != null && header.toLowerCase().startsWith("basic")) {
return header.replaceAll("^[Bb][Aa][Ss][Ii][Cc]", "Basic");
}
return header;
}
};
chain.doFilter(requestWrapper, response);
}
} Registering the Filter: import org.springframework.boot.web.servlet.FilterRegistrationBean;
@Bean
public FilterRegistrationBean<BasicAuthHeaderFilter> filterFilterRegistrationBean(BasicAuthHeaderFilter filter) {
FilterRegistrationBean<BasicAuthHeaderFilter> reg = new FilterRegistrationBean<>(filter);
reg.setOrder(Ordered.HIGHEST_PRECEDENCE);
return reg;
} Thanks again @jeroenheijmans |
FYI: I just got a notification that this was changed in spring-security, slated for milestone "5.0.8". That might make the workaround unneeded. |
Changing the server side implementation for the sake of fixing a client because of a stupid mistake in the library is the most retarded solution I have ever seen. Seriously, if library requires you to hack either your server side app or client you should not use this library in the first place. |
Careful please with your choice of words @ThePinkPanther, it sounds pretty hostile. We're just internet strangers trying to be helpful. About the solution, I think (as indicated by the fact that Spring fixed this on their end) that the server side implementation was the one that had a bug, because it didn't follow the spec originally with a case sensitive comparison. In any case, it won't hurt anyone if you opt to use another library for client side auth. To each their own! 😄 |
Hello,
When configuring the basic authentication header for password flow you are using "Authentication" and the correct header for the scheme is "Authorization"
The text was updated successfully, but these errors were encountered: