Skip to content

feat: Add support for CORS requests from a browser#26314

Merged
mgattozzi merged 1 commit intomainfrom
mgattozzi/cors
Apr 24, 2025
Merged

feat: Add support for CORS requests from a browser#26314
mgattozzi merged 1 commit intomainfrom
mgattozzi/cors

Conversation

@mgattozzi
Copy link
Copy Markdown
Contributor

This commit adds support for CORS by modifying our requests to make preflight checks valid and to handle responses containing the necessary headers for browsers to access the data they need. We keep what we accept as open as this is essentially what requests to the server are normally like and we gate the requests with an auth token.

Closes #26313

This is honestly quite hard to test unless we have a whole headless browser setup going on which for one test seems a bit excessive and it's unlikely this code will change much if at all once committed.

Here you can see that the request to the server fails based off main
Screenshot from 2025-04-22 15-31-25

Here the same request passes with CORS headers enabled
Screenshot from 2025-04-22 15-30-06

This commit adds support for CORS by modifying our requests to make
preflight checks valid and to handle responses containing the necessary
headers for browsers to access the data they need. We keep what we
accept as open as this is essentially what requests to the server are
normally like and we gate the requests with an auth token.

Closes #26313
@mgattozzi mgattozzi requested a review from a team April 22, 2025 19:37
Copy link
Copy Markdown
Contributor

@stuartcarnie stuartcarnie left a comment

Choose a reason for hiding this comment

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

LGTM – should make it much easier for our users 👏🏻

// the following headers. We do this before the API token checks as
// the browser will not send a request with an auth header for CORS.
if let Method::OPTIONS = method {
info!(?uri, "preflight request");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be info, might be noisy

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ahh when I went to merge this comment showed up in my browser tab which I just had open for a few days. We could change it to debug. Wouldn't be a bad thing

@mgattozzi mgattozzi merged commit e684fc1 into main Apr 24, 2025
12 checks passed
@mgattozzi mgattozzi deleted the mgattozzi/cors branch April 24, 2025 19:16
hiltontj pushed a commit that referenced this pull request May 2, 2025
This commit adds support for CORS by modifying our requests to make
preflight checks valid and to handle responses containing the necessary
headers for browsers to access the data they need. We keep what we
accept as open as this is essentially what requests to the server are
normally like and we gate the requests with an auth token.

Closes #26313
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.

Add CORS support for Core and Enterprise

3 participants