Skip to content

fix: handle CORS preflight before authentication#13573

Open
TheSanjBot wants to merge 5 commits into
openfoodfacts:mainfrom
TheSanjBot:fix-cors-preflight-auth
Open

fix: handle CORS preflight before authentication#13573
TheSanjBot wants to merge 5 commits into
openfoodfacts:mainfrom
TheSanjBot:fix-cors-preflight-auth

Conversation

@TheSanjBot
Copy link
Copy Markdown

What

Handle CORS preflight requests before authentication runs.

Browsers dont send authentication cookies with preflight OPTIONS requests, so routes could fail before CORS headers were added. This caused the block

This keeps the change narrow by returning early only for real preflight requests: OPTIONS requests with both Origin and Access-Control-Request-Method headers.

Added a regression test for a facet preflight request.

Large Language Models usage disclosure

Used ChatGPT to understand the CORS code paths

Related issue(s) and discussion

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.43%. Comparing base (f11c7f3) to head (9ebc82e).
⚠️ Report is 33 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13573      +/-   ##
==========================================
+ Coverage   49.21%   54.43%   +5.21%     
==========================================
  Files          97       98       +1     
  Lines       25555    25613      +58     
  Branches     6105     6114       +9     
==========================================
+ Hits        12578    13942    +1364     
+ Misses      11346     9870    -1476     
- Partials     1631     1801     +170     
Flag Coverage Δ
integration-test-group-1 8.94% <ø> (?)
integration-test-group-2 9.11% <ø> (?)
integration-test-group-3 32.83% <ø> (?)
integration-test-group-4 28.53% <ø> (?)
integration-test-group-6 9.47% <ø> (?)
integration-test-group-7 27.66% <ø> (?)
integration-test-group-8 26.36% <ø> (?)
integration-test-group-9 12.92% <ø> (?)
unit-test-group-1 24.63% <ø> (ø)
unit-test-group-2 34.31% <ø> (ø)
unit-test-group-3 23.33% <ø> (ø)
unit-test-group-4 30.14% <ø> (ø)
unit-test-group-5 15.77% <ø> (ø)
unit-test-group-6 27.03% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

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

LGTM, thanks !

@github-project-automation github-project-automation Bot moved this from To discuss and validate to Done in 🍊 Open Food Facts Server issues May 19, 2026
@alexgarel
Copy link
Copy Markdown
Member

Thanks @TheSanjBot ! Really cool.

@alexgarel alexgarel enabled auto-merge (squash) May 19, 2026 13:02
@sonarqubecloud
Copy link
Copy Markdown

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

Projects

Development

Successfully merging this pull request may close these issues.

CORS Preflight (OPTIONS) fails with 503 when authentication is required

4 participants