Skip to content

Commit

Permalink
fix: allow foreign origins to display pdfs
Browse files Browse the repository at this point in the history
  • Loading branch information
rv2e committed Jul 3, 2020
1 parent fe3df49 commit 2fa4097
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v12.18.2
66 changes: 33 additions & 33 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1818,40 +1818,40 @@ const PDFViewerApplication = {

let validateFileURL;
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
const HOSTED_VIEWER_ORIGINS = [
"null",
"http://mozilla.github.io",
"https://mozilla.github.io",
];
// const HOSTED_VIEWER_ORIGINS = [
// "null",
// "http://mozilla.github.io",
// "https://mozilla.github.io",
// ];
validateFileURL = function (file) {
if (file === undefined) {
return;
}
try {
const viewerOrigin = new URL(window.location.href).origin || "null";
if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
// Hosted or local viewer, allow for any file locations
return;
}
const { origin, protocol } = new URL(file, window.location.href);
// Removing of the following line will not guarantee that the viewer will
// start accepting URLs from foreign origin -- CORS headers on the remote
// server must be properly configured.
// IE10 / IE11 does not include an origin in `blob:`-URLs. So don't block
// any blob:-URL. The browser's same-origin policy will block requests to
// blob:-URLs from other origins, so this is safe.
if (origin !== viewerOrigin && protocol !== "blob:") {
throw new Error("file origin does not match viewer's");
}
} catch (ex) {
const message = ex && ex.message;
PDFViewerApplication.l10n
.get("loading_error", null, "An error occurred while loading the PDF.")
.then(loadingErrorMessage => {
PDFViewerApplication.error(loadingErrorMessage, { message });
});
throw ex;
}
// if (file === undefined) {
// return;
// }
// try {
// const viewerOrigin = new URL(window.location.href).origin || "null";
// if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
// // Hosted or local viewer, allow for any file locations
// return;
// }
// const { origin, protocol } = new URL(file, window.location.href);
// // Removing of the following line will not guarantee that the viewer will
// // start accepting URLs from foreign origin -- CORS headers on the remote
// // server must be properly configured.
// // IE10 / IE11 does not include an origin in `blob:`-URLs. So don't block
// // any blob:-URL. The browser's same-origin policy will block requests to
// // blob:-URLs from other origins, so this is safe.
// if (origin !== viewerOrigin && protocol !== "blob:") {
// throw new Error("file origin does not match viewer's");
// }
// } catch (ex) {
// const message = ex && ex.message;
// PDFViewerApplication.l10n
// .get("loading_error", null, "An error occurred while loading the PDF.")
// .then(loadingErrorMessage => {
// PDFViewerApplication.error(loadingErrorMessage, { message });
// });
// throw ex;
// }
};
}

Expand Down

0 comments on commit 2fa4097

Please sign in to comment.