Skip to content

Commit ecf5113

Browse files
committed
Handle forwarded header parse issues
Closes gh-26459
1 parent 80c4e6b commit ecf5113

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

spring-web/src/main/java/org/springframework/web/server/adapter/HttpWebHandlerAdapter.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -228,7 +228,16 @@ public void afterPropertiesSet() {
228228
@Override
229229
public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
230230
if (this.forwardedHeaderTransformer != null) {
231-
request = this.forwardedHeaderTransformer.apply(request);
231+
try {
232+
request = this.forwardedHeaderTransformer.apply(request);
233+
}
234+
catch (Throwable ex) {
235+
if (logger.isDebugEnabled()) {
236+
logger.debug("Failed to apply forwarded headers to " + formatRequest(request), ex);
237+
}
238+
response.setStatusCode(HttpStatus.BAD_REQUEST);
239+
return response.setComplete();
240+
}
232241
}
233242
ServerWebExchange exchange = createExchange(request, response);
234243

0 commit comments

Comments
 (0)