Skip to content

Commit

Permalink
fix(dependency): Issue with kork-web while upgrading spring-boot to 2…
Browse files Browse the repository at this point in the history
….5.14

While upgrading the spring-boot, the compilation of kork-web module failed with following error:
```
> Task :kork-web:compileGroovy FAILED
/kork/kork-web/src/main/java/com/netflix/spinnaker/kork/web/controllers/GenericErrorController.java:41: error: incompatible types: Boolean cannot be converted to ErrorAttributeOptions
        errorAttributes.getErrorAttributes(webRequest, includeStackTrace);
                                                       ^
```

```
/kork/kork-web/src/main/java/com/netflix/spinnaker/kork/web/controllers/GenericErrorController.java:51: error: method does not override or implement a method from a supertype
  @OverRide
  ^
```

```
> Task :kork-web:compileGroovy
/kork/kork-web/src/main/java/com/netflix/spinnaker/kork/web/selector/v2/SelectableService.java uses unchecked or unsafe operations.
startup failed:
/kork/kork-web/src/main/groovy/com/netflix/spinnaker/config/ErrorConfiguration.groovy: 37: Method 'getErrorAttributes' from class 'com.netflix.spinnaker.config.ErrorConfiguration$1' does not override method from its superclass or interfaces but is annotated with @OverRide.
 @ line 37, column 7.
         @OverRide
         ^
```
The root cause is the deprecation of following methods in Spring boot 2.3.x and now removal of code from spring boot 2.5.x:

ErrorAttributes.getErrorAttributes(ServerRequest, boolean)
spring-projects/spring-boot@158933c    spring-projects/spring-boot#21324

ErrorController.getErrorPath()
spring-projects/spring-boot#19844

Fixed the issue with required code changes.
  • Loading branch information
j-sandy committed Oct 18, 2022
1 parent 5836a37 commit 2ec4d48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.netflix.spinnaker.kork.web.exceptions.ExceptionMessageDecorator
import com.netflix.spinnaker.kork.web.exceptions.ExceptionSummaryService
import com.netflix.spinnaker.kork.web.exceptions.GenericExceptionHandlers
import org.springframework.beans.factory.ObjectProvider
import org.springframework.boot.web.error.ErrorAttributeOptions
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes
import org.springframework.boot.web.servlet.error.ErrorAttributes
import org.springframework.context.annotation.Bean
Expand All @@ -35,10 +36,10 @@ class ErrorConfiguration {
final DefaultErrorAttributes defaultErrorAttributes = new DefaultErrorAttributes()
return new ErrorAttributes() {
@Override
Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {
Map<String, Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions includeStackTrace) {
// By default, Spring echoes back the user's requested path. This opens up a potential XSS vulnerability where a
// user, for example, requests "GET /<script>alert('Hi')</script> HTTP/1.1".
Map<String, Object> errorAttributes = defaultErrorAttributes.getErrorAttributes(webRequest, includeStackTrace)
Map<String, Object> errorAttributes = defaultErrorAttributes.getErrorAttributes(webRequest, includeStackTrace.getIncludes().contains(ErrorAttributeOptions.Include.STACK_TRACE))
errorAttributes.remove("path")
return errorAttributes
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.netflix.spinnaker.kork.exceptions.HasAdditionalAttributes;
import java.util.Map;
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -33,12 +34,15 @@ public GenericErrorController(ErrorAttributes errorAttributes) {
this.errorAttributes = errorAttributes;
}

@RequestMapping(value = "/error")
@RequestMapping(value = "${server.error.path:/error}")
public Map error(
@RequestParam(value = "trace", defaultValue = "false") Boolean includeStackTrace,
WebRequest webRequest) {
Map<String, Object> attributes =
errorAttributes.getErrorAttributes(webRequest, includeStackTrace);
ErrorAttributeOptions options =
includeStackTrace
? ErrorAttributeOptions.defaults().including(ErrorAttributeOptions.Include.STACK_TRACE)
: ErrorAttributeOptions.defaults();
Map<String, Object> attributes = errorAttributes.getErrorAttributes(webRequest, options);

Throwable exception = errorAttributes.getError(webRequest);
if (exception != null && exception instanceof HasAdditionalAttributes) {
Expand All @@ -47,9 +51,4 @@ public Map error(

return attributes;
}

@Override
public String getErrorPath() {
return "/error";
}
}

0 comments on commit 2ec4d48

Please sign in to comment.