CORS with Spring Boot - restrict GET requests to certain domains

Viewed 1307

I am using Spring Boot and would like to restrict HTTP GET requests only from certain domains. For example, I would like to accept requests only from a list of predefined domains (e.g. https://www.frontend.com, https://www.test-frontend.com). How could I implement such a functionality?

I expected to face CORS issues, but theses do not apply for GET requests. Any ideas?

2 Answers

First .allowedMethods use for allow methods so if you don't want to allow "GET" then put all others methods but do not put GET method, like below:

.allowedMethods("PUT", "DELETE", "PATCH")

and second you can not CORS by non-webapp clients like curl or Postman, any non web app client.

Related