Super-short instructions how to place the breakpoint in an IDE in order to debug CORS issues in Spring Boot.

The problem with debugging CORS (like any other filter in spring boot security) is, that any request is blocked before they even enter any code of your own application. This can create quite some headaches how to debug the problem, if none of the breakpoints within the applications are ever passed.

One possible solution is to set the breakpoint within the spring-web jar as shown below.

Step 0: Download Maven sources, if not already done

In the Maven Pane, look for the download icon and download the sources:

Download Sources in the Maven Pane

Step 1: Set the Breakpoint within spring-web

  1. In IntelliJ IDEA, on the left project pane, look for Maven: org.springframework:spring-web:x.y.z.
  2. Enter the file web/cors/CorsConfiguration.
  3. Look for the pattern/function public String checkOrigin
  4. Set a Breakpoint on the first line after the pattern

Step 2: Start a debugging Session and send the request to the application

  1. Start the the application in a debugging session
  2. Send the request to the application

Step 3: Compare requestOrigin with allowedOrigins

  1. Look at the variables
    • requestOrigin
    • allowedOrigins

In the example below, the requestOrigin „http://localhost:8081“ is not in the list allowedOrigins and will fail.

Set a breakpoint in checkOrigin function ofspring-web JAR

Add the requestOrigin to the list of security.allowedOrigins, if needed. In my case, I had to edit the application.yaml file. However, it might be a different story in your case.

Adding origin to security.allowed-origins to application.yaml

DONE

Further Reading

Comments

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.