Skip to content
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

CORS Policy only works with public APIs #2475

Open
volkflo opened this issue Mar 1, 2023 · 0 comments
Open

CORS Policy only works with public APIs #2475

volkflo opened this issue Mar 1, 2023 · 0 comments

Comments

@volkflo
Copy link
Member

volkflo commented Mar 1, 2023

Apiman Version

3

Apiman Manager Distro

Tomcat

Apiman Gateway Distro

Vert.x

Java Version

11 LTS

Operating System

Linux

Are you running Apiman in a container, or on an orchestration platform?

Docker Compose

Describe the bug

It seems that the CORS policy only works 100% correctly if the API is public.

If the API is private the x-api-key is checked at first stage before the policy chain is loaded and executed.
However, the browser will send for all non-simple methods a preflight (OPTIONS) request.

The problem is that the browser only attaches the minimum headers to this request.
So our custom x-api-key header is never attached to this OPTIONS request made by the browser.

In that case the OPTIONS request will be blocked ("API not public") and we are never able to get into the policy chain to execute the CORS policy. So the CORS request is blocked before it can reach the CORS policy.

This seems to be as per design as the preflight request only contains these headers:

Access-Control-Request-Method: DELETE
Access-Control-Request-Headers: origin, x-requested-with
Origin: https://foo.bar.org

See infos:

Expected behaviour

TBH, I am not totally sure what would be the best way to handle this situation.
I guess the gateway should handle OPTION requests differently than a "normal" requests, but I am not sure if this is a good idea. But that would require some deeper modifications.

Actual behaviour

No response

How to Reproduce

  1. Set up a private API, and attach the CORS Policy (the configuration can be a minimum, just add * for allowed origins)
  2. Try to send an options request (without x-api-key as the browser would sent it)

Relevant log output

No response

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant