Skip to content

fix(api): allow unauthenticated OPTIONS (CORS preflight) requests - #704

Open
Manny7717 wants to merge 1 commit into
Exodus-Privacy:v1from
Manny7717:fix/cors-preflight
Open

fix(api): allow unauthenticated OPTIONS (CORS preflight) requests#704
Manny7717 wants to merge 1 commit into
Exodus-Privacy:v1from
Manny7717:fix/cors-preflight

Conversation

@Manny7717

Copy link
Copy Markdown

What

CORS preflight requests always use credentials mode omit, so the API must answer OPTIONS requests without requiring authentication (per the Fetch spec). Previously every API view applied IsAuthenticated to all methods, so a preflight returned 401 (repro in #319: curl -X OPTIONS .../api/search/test{\"detail\":\"Authentication credentials were not provided.\"}).

Change

  • New IsAuthenticatedOrOptions permission: passes OPTIONS through, delegates to IsAuthenticated for everything else.
  • Applied to all API views in restful_api/views.py (regular and admin-gated views). Authenticated endpoints are unchanged: GET/HEAD/POST/etc. still require a valid token.

Tests

  • New regression test test_options_preflight_does_not_require_auth: unauthenticated OPTIONS /api/applications now returns 200 (was 401, verified by running the test without the fix).
  • manage.py test restful_api → 41/41 OK; full suite → 69/69 OK; flake8 clean.

CORS preflight requests always omit credentials, so the API must
answer them without requiring authentication (Fetch spec). The API
views previously applied IsAuthenticated to every method, returning
401 on OPTIONS. Adds an IsAuthenticatedOrOptions permission that
passes OPTIONS through and uses it on all API views. Closes Exodus-Privacy#319
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.

1 participant