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 preflight OPTIONS requests should bypass authentication #78

Closed
nitper opened this issue Apr 6, 2019 · 5 comments · Fixed by #86
Closed

CORS preflight OPTIONS requests should bypass authentication #78

nitper opened this issue Apr 6, 2019 · 5 comments · Fixed by #86
Assignees
Labels
Milestone

Comments

@nitper
Copy link
Contributor

nitper commented Apr 6, 2019

Describe the bug
Pomerium is requiring authentication for http OPTIONS requests, but the spec says OPTIONS requests should not include user credentials. These requests should be passed downstream without authentication.

To Reproduce Steps to reproduce the behavior:

Browser on https://bob.corp.domain.com/ makes a CORS request to https://alice.corp.domain.com/ like this:

curl 'https://alice.corp.domain.com/api/route' -X OPTIONS -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0' -H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Access-Control-Request-Method: POST' -H 'Access-Control-Request-Headers: content-type' -H 'Origin: https://bob.corp.domain.com' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Referer: https://bob.corp.domain.com/some/route' -H 'TE: Trailers'

Pomerium will try to redirect to the authentication provider.

Expected behavior

Pomerium should not require auth for HTTP OPTIONS requests.

Environment:

  • Pomerium version (retrieve with pomerium --version): v0.0.3+41c42f5
  • Server Operating System/Architecture/Cloud: ubuntu 18.04, running on EC2 behind an elastic ip

Configuration file(s):

Logs(s):

ERR authenticate: failed to load session error="http: named cookie not present" 
WRN authenticate: authenticate error error="http: named cookie not present" 
@nitper
Copy link
Contributor Author

nitper commented Apr 6, 2019

I did some searching around, and there are a bunch of other proxy projects that have implemented this. Here's one example https://github.com/istio/proxy/issues/651

@desimone
Copy link
Contributor

desimone commented Apr 7, 2019

Hi @nitper thank you bug report.

I didn't know that about OPTIONS. We should conform to the spec, but I would like to better understand the use-case and investigate a bit regarding any potential security implications of having a bypass.

Could you point me in the direction right direction to read more about OPTIONS?

Ref for later self:

@desimone desimone added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 7, 2019
@desimone desimone added this to the v0.0.4 milestone Apr 7, 2019
@nitper
Copy link
Contributor Author

nitper commented Apr 7, 2019

Your second link as well as the spec I posted originally are the best resources I have seen. There are various blog posts out there but they all seem to reference these two links.

There's also this page https://enable-cors.org/server.html which links to this handy server flowchart. Since Pomerium is a proxy, I believe it should verify that an OPTIONS request has all the necessary headers to qualify it as preflight, and then forward that to the server without authentication.

I'll need to double-check this, but it seems the preflight OPTIONS request must include these headers:


For what it's worth, my downstream server is using Echo as the server with the CORS middleware.

My frontend is using axios setting withCredentials: true

  // `withCredentials` indicates whether or not cross-site Access-Control requests
  // should be made using credentials
  withCredentials: false, // default

Pomerium is working just fine with this setup for CORS simple requests

@nitper
Copy link
Contributor Author

nitper commented Apr 8, 2019

@desimone I'd be happy to submit a PR.

I was thinking about adding a field cors_allow_preflight (not married to the name) to Policy with a default of false. This way the user can manually and intentionally enable the unauthenticated passthrough of OPTIONS requests for each route as needed.

What do you think?

@desimone
Copy link
Contributor

desimone commented Apr 8, 2019

@nitper Thank you, a PR would be greatly appreciated!

I think the field name of cors_allow_preflight makes sense, and agree that defaulting to "off" is a safe choice.

More reading for future travelers:

@desimone desimone added accepted and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Apr 8, 2019
@desimone desimone modified the milestones: v0.0.4, v0.0.5 May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants