Browse Source

ServerHttpBasicAuthenticationConverter Validates Scheme Name

Fixes: gh-5414
pull/5618/head
Rob Winch 8 years ago
parent
commit
0c26d1b98a
  1. 2
      web/src/main/java/org/springframework/security/web/server/ServerHttpBasicAuthenticationConverter.java
  2. 16
      web/src/test/java/org/springframework/security/web/server/ServerHttpBasicAuthenticationConverterTests.java

2
web/src/main/java/org/springframework/security/web/server/ServerHttpBasicAuthenticationConverter.java

@ -41,7 +41,7 @@ public class ServerHttpBasicAuthenticationConverter implements Function<ServerWe @@ -41,7 +41,7 @@ public class ServerHttpBasicAuthenticationConverter implements Function<ServerWe
ServerHttpRequest request = exchange.getRequest();
String authorization = request.getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
if(authorization == null) {
if(authorization == null || !authorization.toLowerCase().startsWith("basic ")) {
return Mono.empty();
}

16
web/src/test/java/org/springframework/security/web/server/ServerHttpBasicAuthenticationConverterTests.java

@ -79,6 +79,22 @@ public class ServerHttpBasicAuthenticationConverterTests { @@ -79,6 +79,22 @@ public class ServerHttpBasicAuthenticationConverterTests {
assertThat(authentication.getCredentials()).isEqualTo("password");
}
@Test
public void applyWhenLowercaseSchemeThenAuthentication() {
Mono<Authentication> result = apply(this.request.header(HttpHeaders.AUTHORIZATION, "basic dXNlcjpwYXNzd29yZA=="));
UsernamePasswordAuthenticationToken authentication = result.cast(UsernamePasswordAuthenticationToken.class).block();
assertThat(authentication.getPrincipal()).isEqualTo("user");
assertThat(authentication.getCredentials()).isEqualTo("password");
}
@Test
public void applyWhenWrongSchemeThenAuthentication() {
Mono<Authentication> result = apply(this.request.header(HttpHeaders.AUTHORIZATION, "token dXNlcjpwYXNzd29yZA=="));
assertThat(result.block()).isNull();
}
private Mono<Authentication> apply(MockServerHttpRequest.BaseBuilder<?> request) {
return this.converter.apply(MockServerWebExchange.from(this.request.build()));
}

Loading…
Cancel
Save