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

Add Access-Control-Allow-Origin response header #4367

Merged
merged 3 commits into from
Feb 7, 2023
Merged

Conversation

yifanmai
Copy link
Contributor

@yifanmai yifanmai commented Jan 26, 2023

Reasons for making this change

This allows websites not hosted CodaLab to make XMLHttpRequests to fetch files from CodaLab bundles.

Related issues

Addresses #4365

Checklist

  • I've added a screenshot of the changes, if this is a frontend change
  • I've added and/or updated tests, if this is a backend change
  • I've run the pre-commit.sh script
  • I've updated docs, if needed

@yifanmai
Copy link
Contributor Author

My initial assessment that the header can only be added for public bundles is incorrect. It is safe to add the header to all responses, even for private bundles, because of the how requests with credentials work:

By default, in cross-origin XMLHttpRequest or Fetch invocations, browsers will not send credentials. A specific flag has to be set on the XMLHttpRequest object or the Request constructor when it is invoked... the browser will reject any response that does not have the Access-Control-Allow-Credentials: true header, and not make the response available to the invoking web content.

- `Target-Type: file`
- `X-CodaLab-Target-Size: <size of the target>`

HTTP Response headers (for directories):
- `Content-Disposition: attachment; filename=<bundle or directory name>.tar.gz`
- `Content-Type: application/gzip`
- `Content-Encoding: identity`
- `Access-Control-Allow-Origin: *` (only sent if the bundle is public)
Copy link
Member

Choose a reason for hiding this comment

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

Please update this documentation to remove the "only sent if the bundle is public" part

@yifanmai yifanmai merged commit 0bd9c05 into master Feb 7, 2023
@yifanmai yifanmai deleted the yifanmai/4365-cors branch February 7, 2023 17:40
@wwwjn wwwjn mentioned this pull request Feb 10, 2023
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.

None yet

3 participants