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: Fetch manifest with credentials over CORS #5156

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

samvrlewis
Copy link

Summary

When behind authentication (for eg: Cloudflare Access), browsers won't send credentials when fetching the manifest file by default.

To fix, this change adds crossorigin="use-credentials" to the manifest link tag which allows the browser to attach credentials. Because of limitations with Vite, for now this needs to happen as a manual post build step.

Change Type

Please delete any irrelevant options.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Translation update

Testing

Ran npm run frontend and ensured the manifest link in client/dist/index.html had the expected crossorigin attribute.

Test Configuration:

Checklist

Please delete any irrelevant options.

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code

When behind authentication (for eg: Cloudflare Access), browsers
won't send credentials when fetching the manifest file by default.

To fix, this change adds `crossorigin="use-credentials"` to the
manifest link tag which allows the browser to attach credentials.
Because of limitations with Vite, for now this needs to happen as
a manual post build step.
/<link\s+rel=["']manifest["']([^>]*)>/i,
(_, attributes) => `<link rel="manifest"${attributes} crossorigin="use-credentials">`
);
await writeFile(indexPath, html);
Copy link
Author

Choose a reason for hiding this comment

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

Happy to hear if there's a better way of doing this. I tried initially with a plugin that used transformIndexHtml but it appears this runs before the manifest link is injected, this approach was the only way I could get it to work.

Slightly frustrating that there isn't an easier way to configure this in vite!

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