[Pkg-javascript-commits] [pdf.js] 09/14: Allow foriegn origin URLs only of hosted viewers.
David Prévot
taffit at moszumanska.debian.org
Sat Jan 30 19:19:51 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit d1e83b58e6e27c4cb70b7714dc0beff478b34269
Author: Yury Delendik <ydelendik at mozilla.com>
Date: Fri Jan 15 18:32:17 2016 -0600
Allow foriegn origin URLs only of hosted viewers.
---
web/viewer.js | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/web/viewer.js b/web/viewer.js
index c8d1dda..7226cc1 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -1329,6 +1329,37 @@ window.PDFView = PDFViewerApplication; // obsolete name, using it as an alias
//})();
//#endif
+//#if GENERIC
+var HOSTED_VIEWER_ORIGINS = ['null',
+ 'http://mozilla.github.io', 'https://mozilla.github.io'];
+function validateFileURL(file) {
+ try {
+ var viewerOrigin = new URL(window.location.href).origin || 'null';
+ if (HOSTED_VIEWER_ORIGINS.indexOf(viewerOrigin) >= 0) {
+ // Hosted or local viewer, allow for any file locations
+ return;
+ }
+ var fileOrigin = new URL(file, window.location.href).origin;
+ // 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.
+ if (fileOrigin !== viewerOrigin) {
+ throw new Error('file origin does not match viewer\'s');
+ }
+ } catch (e) {
+ var message = e && e.message;
+ var loadingErrorMessage = mozL10n.get('loading_error', null,
+ 'An error occurred while loading the PDF.');
+
+ var moreInfo = {
+ message: message
+ };
+ PDFViewerApplication.error(loadingErrorMessage, moreInfo);
+ throw e;
+ }
+}
+//#endif
+
function webViewerLoad(evt) {
PDFViewerApplication.initialize().then(webViewerInitialized);
}
@@ -1338,6 +1369,7 @@ function webViewerInitialized() {
var queryString = document.location.search.substring(1);
var params = parseQueryString(queryString);
var file = 'file' in params ? params.file : DEFAULT_URL;
+ validateFileURL(file);
//#endif
//#if (FIREFOX || MOZCENTRAL)
//var file = window.location.href.split('#')[0];
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list