-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error 403 forbidden POST login using localhost #8560
Comments
Maybe it's related to #8582 |
We changed the behaviour in 3.8.x to prevent drive-by localhost attack. My recommendation is you add configuration only for the swagger origin. Instead of something as broad as :
|
For me requesting localhost:8080 (my micronaut service) from localhost:4200 (my local ui) did throw the same error. Is that intended? I fixed it by requesting 127.0.0.1:8080 instead (do not ask my why it works, it just does) |
I think if your app is running in localhost and the front end is running in localhost. You should be able to do:
Currently you will need to do:
I will try to change this for 3.8.1 |
Closed via #8601 |
Thank you for being so quick with the fix 🎉, there is just one thing left
I think while this ticket is closed, that there is still a bug. If your statement is true requesting the api on So from a security perspective i believe that attackers would just need to change the drive by url from localhost to any local address. It is not a new security issue but should be fixed imo since users could believe they are safe when they are not.
|
@timyates could you consider the suggestions from @nbrugger-tgm ? |
@nbrugger-tgm Could you take a look at #8642 Thanks for all the help 👍 |
Expected Behavior
The POST /login response with http status 200 and CORS headers included.
Micronaut 3.7.4
curl -i -v 'http://localhost:8080/login' -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Referer: http://localhost:8090/' -H 'Content-Type: application/x-www-form-urlencoded' -H 'X-Requested-With: XMLHttpRequest' -H 'Authorization: Basic Og==' -H 'Origin: http://127.0.0.1:8090/' -H 'Connection: keep-alive' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-site' --data-raw 'grant_type=password&username=admin&password=admin'
Micronaut 3.8.0 host different than localhost
curl -i -v 'http://127.0.0.1:8080/login' -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Referer: http://localhost:8090/' -H 'Content-Type: application/x-www-form-urlencoded' -H 'X-Requested-With: XMLHttpRequest' -H 'Authorization: Basic Og==' -H 'Origin: http://127.0.0.1:8090/' -H 'Connection: keep-alive' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-site' --data-raw 'grant_type=password&username=admin&password=admin'
Actual Behaviour
I use swagger to expose the Rest API documentation. The authentication process call the login endpoint in a different server (I use an auth-server running in other server than the business microservices).
Upgrading to micronaut 3.8.0 version the remote login in swagger doesn't work anymore (the login response is 403 forbidden). After check configuration and differents test using CURL I realize that the CORS headers isn't included in the response. Checking the source code I found some validations when the host is localhost that explain the 403 status code but for example the ip 127.0.0.1 isn't included. Is that correct?
In order to solve this problem I have to include the following configuration to use swagger in local environment
micronaut: server: cors: enabled: true configurations: web: allowedOrigins: - ^http(|s):\/\/*.*
In previous version the mentioned configuration wasn't need to include and CURL and swagger works perfectly.
In the Example Application can reproduce the behavior mentioned using the following curl
curl -i -v 'http://localhost:8080/login' -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Referer: http://localhost:8090/' -H 'Content-Type: application/x-www-form-urlencoded' -H 'X-Requested-With: XMLHttpRequest' -H 'Authorization: Basic Og==' -H 'Origin: http://127.0.0.1:8090/' -H 'Connection: keep-alive' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-site' --data-raw 'grant_type=password&username=admin&password=admin'
Steps To Reproduce
1- Clone the example application repository
2- ./gradlew run
3- Execute this curl command
Using localhost
curl -i -v 'http://localhost:8080/login' -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Referer: http://localhost:8090/' -H 'Content-Type: application/x-www-form-urlencoded' -H 'X-Requested-With: XMLHttpRequest' -H 'Authorization: Basic Og==' -H 'Origin: http://127.0.0.1:8090/' -H 'Connection: keep-alive' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-site' --data-raw 'grant_type=password&username=admin&password=admin'
Using 127.0.0.1
curl -i -v 'http://127.0.0.1:8080/login' -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Referer: http://localhost:8090/' -H 'Content-Type: application/x-www-form-urlencoded' -H 'X-Requested-With: XMLHttpRequest' -H 'Authorization: Basic Og==' -H 'Origin: http://127.0.0.1:8090/' -H 'Connection: keep-alive' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-site' --data-raw 'grant_type=password&username=admin&password=admin'
Environment Information
Manjaro, Ubuntu
OpenJDK 17, 18
It works fine in Micronaut 3.7.4 and Micronaut 3.7.5
Example Application
https://github.com/fercapi84/cors-localhost-conf
Version
3.8.0
The text was updated successfully, but these errors were encountered: