Skip to content

DEV: Simplify CORS logic for public asset routes #33106

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

Merged
merged 3 commits into from
Jun 9, 2025
Merged

Conversation

davidtaylorhq
Copy link
Member

@davidtaylorhq davidtaylorhq commented Jun 6, 2025

Previously we would check the request for a matching CDN hostname before applying the Access-Control-Allow-Origin header. That logic requires the CDN to include its public-facing hostname in the Host header, which is not always the case.

Since we are only running this apply_cdn_headers before_action on publicly-accessible asset routes, we can simplify things so that the Access-Control-Allow-Origin: * header is always included. That will make CDN config requirements much more relaxed.

At the moment, this is primarily relevant to the HighlightJsController routes, which are loaded using native JS type=module. But in the near future, we plan to expand our use of type=module to more critical JS assets like translations and themes.

Also drops the Access-Control-Allow-Methods header from these responses. That isn't needed for GET and HEAD requests.

Previously we would check the request for a matching CDN hostname before applying the `Access-Control-Allow-Origin` header. That logic requires the CDN to include its public-facing hostname in the `Host` header, which is not always the case.

Since we are only running this `apply_cdn_headers` before_action on publicly-accessible asset routes, we can simplify things so that the `Access-Control-Allow-Origin: *` header is always included.

At the moment, this is primarily relevant to the HighlightJsController routes, which are loaded using native JS `type=module`. But in the near future, we plan to expand our use of `type=module` to more critical JS assets like translations and themes.
@davidtaylorhq davidtaylorhq changed the title FEATURE: Simplify CORS logic for public assets DEV: Simplify CORS logic for public assets Jun 6, 2025
That's only needed for preflight, which isn't needed for 'simple requests' like GET and HEAD
@davidtaylorhq davidtaylorhq changed the title DEV: Simplify CORS logic for public assets DEV: Simplify CORS logic for public asset routes Jun 6, 2025
@davidtaylorhq davidtaylorhq marked this pull request as ready for review June 6, 2025 15:34
@davidtaylorhq davidtaylorhq merged commit 27227c9 into main Jun 9, 2025
16 checks passed
@davidtaylorhq davidtaylorhq deleted the asset-cors branch June 9, 2025 07:58
martin-brennan pushed a commit that referenced this pull request Jun 10, 2025
Previously we would check the request for a matching CDN hostname before
applying the `Access-Control-Allow-Origin` header. That logic requires
the CDN to include its public-facing hostname in the `Host` header,
which is not always the case.

Since we are only running this `apply_cdn_headers` before_action on
publicly-accessible asset routes, we can simplify things so that the
`Access-Control-Allow-Origin: *` header is always included. That will
make CDN config requirements much more relaxed.

At the moment, this is primarily relevant to the HighlightJsController
routes, which are loaded using native JS `type=module`. But in the near
future, we plan to expand our use of `type=module` to more critical JS
assets like translations and themes.

Also drops the `Access-Control-Allow-Methods` header from these
responses. That isn't needed for `GET` and `HEAD` requests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants