Skip to content

Commit b6e24db

Browse files
committed
Return Mono.empty on Empty POST
Closes gh-18973 Signed-off-by: Josh Cummings <3627351+jzheaux@users.noreply.github.com>
1 parent aeb5fc1 commit b6e24db

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

web/src/main/java/org/springframework/security/web/server/authentication/ott/ServerOneTimeTokenAuthenticationConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public Mono<Authentication> convert(ServerWebExchange exchange) {
4949
Assert.notNull(exchange, "exchange cannot be null");
5050
if (isFormEncodedRequest(exchange.getRequest())) {
5151
return exchange.getFormData()
52-
.map((data) -> OneTimeTokenAuthenticationToken.unauthenticated(data.getFirst(TOKEN)));
52+
.mapNotNull((data) -> data.getFirst(TOKEN))
53+
.map((data) -> OneTimeTokenAuthenticationToken.unauthenticated(data));
5354
}
5455
String token = resolveTokenFromRequest(exchange.getRequest());
5556
if (!StringUtils.hasText(token)) {

web/src/test/java/org/springframework/security/web/server/authentication/ott/ServerOneTimeTokenAuthenticationConverterTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ void convertWhenNoTokenParameterThenNull() {
7272
assertThat(authentication).isNull();
7373
}
7474

75+
// gh-18973
76+
@Test
77+
void convertWhenNoTokenFormParameterThenNull() {
78+
MockServerHttpRequest request = MockServerHttpRequest.post("/")
79+
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
80+
.body("username=Max");
81+
82+
Authentication authentication = this.converter.convert(MockServerWebExchange.from(request)).block();
83+
84+
assertThat(authentication).isNull();
85+
}
86+
7587
@Test
7688
void convertWhenTokenEncodedFormParameterThenReturnOneTimeTokenAuthenticationToken() {
7789
// @formatter:off

0 commit comments

Comments
 (0)