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

Correctly set CORS header for Stanford Only files #1066

Open
edsu opened this issue Dec 6, 2023 · 7 comments · May be fixed by #1068
Open

Correctly set CORS header for Stanford Only files #1066

edsu opened this issue Dec 6, 2023 · 7 comments · May be fixed by #1068

Comments

@edsu
Copy link

edsu commented Dec 6, 2023

In order for PDF and 3D Objects to be viewable in sul_embed JavaScript needs to fetch the file (PDF or GLB) from Stacks. This works fine in cases where the file is public. But if the file is Stanford Only the fetch request needs to include credentials (assuming they are logged in) or else the request will be denied.

Unfortunately, it's not possible to send credentials unless Stacks sends Access-Control-Allow-Origin: embed.stanford.edu in its response instead of Access-Control-Allow-Origin: embed.stanford.edu: *. From the MDN docs:

Note: Access-Control-Allow-Origin is prohibited from using a wildcard for requests with credentials: 'include'. In such cases, the exact origin must be provided; even if you are using a CORS unblocker extension, the requests will still fail.

It's also important that Stacks send this header ONLY when responding to requests for Stanford Only items. Otherwise JavaScript applications running outside of embed.stanford.edu will no longer be able to access public files.

It looks to me like the proposed work in #1063 would send the correct CORS header when a Stanford Only file is being sent? This was only for the auth controller, and now for viewing files. But I believe similar logic would be needed to only send the host specific CORS header when an attempt is being made to view a Stanford Only item?

See also: sul-dlss/sul-embed#1642

@edsu edsu changed the title Correctly set Access-Control-Allow-Origin when serving Stanford Only files Correctly set CORS header when serving Stanford Only files Dec 6, 2023
@edsu edsu changed the title Correctly set CORS header when serving Stanford Only files Correctly set CORS header for Stanford Only files Dec 6, 2023
@jcoyne
Copy link
Contributor

jcoyne commented Dec 7, 2023

@edsu That documentation is for a fetch request. Are we sending a fetch request for a file?

@edsu
Copy link
Author

edsu commented Dec 7, 2023

pdfjs has a withCredentials option to send credentials which we would need to set to true for Stanford Only items. The model-viewer web component has a similar property with-credentials. I believe both use XMLHttpRequest underneath, but I would expect the security model to be the same as fetch?

@jcoyne
Copy link
Contributor

jcoyne commented Dec 7, 2023

Oh, I thought we had switched to the native pdf viewer.

@edsu
Copy link
Author

edsu commented Dec 8, 2023

Not yet, alas. A decision has yet to be made, and embedding is a feature flag that is turned on in stage/uat. But you're right, embedding will make this problem go away for PDF.

@jcoyne
Copy link
Contributor

jcoyne commented Dec 11, 2023

@edsu What is the decision timeline for the embedding?

@edsu
Copy link
Author

edsu commented Dec 12, 2023

Unfortunately, I don't think there is one, unless I'm the last to know.

@lwrubel
Copy link

lwrubel commented Dec 18, 2023

This depends on what we learn through sul-dlss/sul-embed#1944 and represents another possible solution.

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 a pull request may close this issue.

3 participants