skip to Main Content

In my current project we deploy several Spring Boot 1.5.4.RELEASE microservices in Openshift with Kubernetes. We have configured an Apache Proxy Balancer:

From                            To
/msa/microname1          ->     /
/msa/microname2          ->     /
...

Recently we introduced Spring Boot 2 and we developed a new microservice with Kotlin. We configured the balancer the same way considering that urls like /health and /info are placed under /actuator path.
Now when we consume any endpoint of this new microservice (/health or any of our endpoints) we are having an error like this:

org.springframework.security.web.firewall.RequestRejectedException:
The request was rejected because the URL was not normalized …

The path that we intercept in our microservice has an extra slash in the beginning: //<path_to_resource>

When I use the microservice url I get the resource without problems, but when using the proxy balancer mapping we have the issue described above.

We checked our proxy balancer and it is configured the same way than the others.
Is is any extra configuration on Spring Boot 2 we have to consider?
Can this be a problem related to Kotlin?

Update

As a tweak we have configured the DefaultHttpFirewall to allow url enconded slash, but this does not fixes the issue with the double slash. It only masks the problem.

@Bean
fun allowUrlEncodedSlash(): HttpFirewall {
    var firewall: DefaultHttpFirewall = DefaultHttpFirewall()
    firewall.setAllowUrlEncodedSlash(true)
    return firewall
}

override fun configure(web: WebSecurity) {
    web.httpFirewall(allowUrlEncodedSlash())
}

2

Answers


  1. Chosen as BEST ANSWER

    Solved by adding context to the application in our balancer. Now all our endpoints have a context in our microservice, defined in application.yml.

    From                            To
    /msa/microname1          ->     /
    /msa/microname2          ->     /
    /msa/Kotlinname/kt       ->     /kt
    

  2. Check this answer: https://stackoverflow.com/a/48644226/10451721

    It seems to be the same issue as yours but in Java instead of Kotlin.

    Spring doesn’t like // in URLs by default.

    I have converted the Java in the linked answer for you:

    @Bean
    fun allowUrlEncodedSlashHttpFirewall(): HttpFirewall {
        val firewall = StrictHttpFirewall()
        firewall.setAllowUrlEncodedSlash(true)
        return firewall
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search