Here's my issue. My server is configured for CORS and the preflight request works fine:
$> curl 'https://db.mywebsite.com/something/_search' -X 'OPTIONS' ...
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Allow: GET,POST
< Content-Length: 0
< Content-Type: text/plain; charset=UTF-8
< Date: Tue, 20 Apr 2021 06:18:36 GMT
As you can see, it is set up to allow every origin (since allowing the proper origin did not work I tried with * and the problem persists.)
When making the subsequent actual request though, here is what I'm getting:
$> curl 'https://db.mywebsite.com/something/_search' -X 'POST' -H 'origin: https://mywebsite.com/' ...
< HTTP/1.1 403 Forbidden
< Access-Control-Allow-Origin: *
< Content-Length: 0
< Date: Tue, 20 Apr 2021 06:20:02 GMT
And interestingly, if I remove the origin header, it works fine, so this rules out that the 403 would come from the backend server.
When I look for similar problems online I only end up on cases where the preflight requests get 403s but I couldn't find anything similar to what I'm facing here. Any idea what it could be due to?