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

Fix list of allowed verbs for failed (unauthorized) preflight #4

Merged
merged 3 commits into from
Jun 11, 2018

Conversation

jldiaz
Copy link

@jldiaz jldiaz commented Jun 11, 2018

During preflight (OPTIONS verb) no Authorization headers can be
provided. Some apps (see for example this issue)
require these headers to determine the identity,
when solving a path and associating it with a model (eg: imagine that
the model is a User whose identity is in that header). Without that
information a sensible action for the path function is to raise
HTTPUnauthorized.

The problem is that more.cors treats that exception (and any exception)
in the same way during preflight: a 404 error is returned and no cors
headers. This prevents the browser to continue with the operation, which
could be otherwise legal.

This patch causes more.cors to return valid cors headers even if
the path function raised HTTPUnauthorized, instead of no cors headers.

During preflight (OPTIONS verb) no Authorization headers can be
provided. Some apps requirese these headers to determine the identity,
when solving a path and associating it with a model (eg: imagine that
the model is a User whose identity is in that header). Without that
information a sensible action for the path function is to raise
HTTPUnauthorized.

The problem is that more.cors treats that exception (and any exception)
in the same way during preflight: a 404 error is returned and no cors
headers. This prevents the browser to continue with the operation, which
could be otherwise legal.

This patch causes more.cors to return valid cors headers even if
the path function raised HTTPUnauthorized, instead of no cors headers.
@henri-hulski
Copy link
Member

henri-hulski commented Jun 11, 2018

Thanks for looking into that issue.
Your solution looks fine to me.
There is just a minor pep8 issue:

more/cors/main.py:31:18: E711 comparison to None should be 'if cond is None:'
        if model == None:

It would also be good if you could add a test as we try to force 100% coverage.
With your patch line 32 and 99 of main.py are not covered.

Copy link
Member

@henri-hulski henri-hulski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@henri-hulski henri-hulski merged commit d5d1ae6 into morepath:master Jun 11, 2018
@henri-hulski
Copy link
Member

@jldiaz I have released more.cors version 0.2.
Could you check if it works now?

@jldiaz
Copy link
Author

jldiaz commented Jun 11, 2018

Yes, the problem with the failed preflights is gone.

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

Successfully merging this pull request may close these issues.

3 participants