-
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
An empty-string bearer token should result in an appropriate HTTP status code #15885
Comments
Thanks for reaching out @jacknie84!
This is standard practice throughout the Spring Security codebase and Spring at large. The contract for
I'm sorry you're seeing an error you don't want. Typically, an Regardless, assuming the request is unauthenticated, Spring Security protects the |
@sjohnr Thanks for your response. I will create a sample right away and share it with you. |
Thanks @jacknie84. Please note that I just spotted this line in your configuration:
This leaves part of your application unprotected, including In any case, a 500 would still be returned for uathenticated users, and you need to set up error handling for that exception if you want to customize the response. If I've missed something feel free to continue providing a sample, but if that line is the reason you're seeing 500 for unauthenticated users (I believe it is) then please don't feel the need to provide a sample. |
Thanks @sjohnr If the configuration line you mentioned is removed, when an I think it should be processed so that a I have prepared a simple sample. When you start the sample application server I prepared, you can request the Please check my PR for information on how to request the |
@jacknie84 thanks for your reply and sample.
I would recommend that the entire application be protected unless it is not possible for some other reason.
Spring Security uses a secure-by-default approach, so this is by design. If necessary, you can permit the @Configuration
@EnableWebSecurity
public class SecurityConfiguration {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
...
.authorizeHttpRequests(authorize -> authorize
// Either of the following lines will display errors
.dispatcherTypeMatchers(DispatcherType.ERROR).permitAll()
.requestMatchers("/error").permitAll()
...
.anyRequest().authenticated()
);
return http.build();
}
}
An empty token value is not a malformed token, but is invalid input. The In RFC 6750, it defines an error for
This error could be appropriate to return in this case. This change could be made in both |
Issue spring-projectsgh-15885(집에 가서 통합 테스트 확인)
Thanks @sjohnr
Thank you for the detailed explanation. I got it.
If I see that an empty string of tokens is requested in DefaultBearerTokenResolver and ServerBearerTokenAuthenticationConverter, I prepared a PR that responds with a 400 error. |
Describe the bug
If
allowFormEncodedBodyParameter
orallowUriQueryParameter
ofDefaultBearerTokenResolver
is set totrue
, a token will be retrieved from the request parameter.If the token is an
empty string
rather thannull
, anIllegalArgumentException
will be thrown when creating aBearerTokenAuthenticationToken
instance in thedoFilterInternal
method code ofBearerTokenAuthenticationFilter
.In that case, the HTTP response code will be
500
(Internal Server Error).I don't think this is an accurate response, and I think it should be a
401
(Unauthorized) response.To Reproduce
build.gradle
Configuration
curl
server log exception trace
Expected behavior
I think it should be a 401 (Unnauthoized) response.
The text was updated successfully, but these errors were encountered: