@@ -1329,6 +1329,37 @@ window.PDFView = PDFViewerApplication; // obsolete name, using it as an alias
13291329//})();
13301330//#endif
13311331
1332+ //#if GENERIC
1333+ var HOSTED_VIEWER_ORIGINS = [ 'null' ,
1334+ 'http://mozilla.github.io' , 'https://mozilla.github.io' ] ;
1335+ function validateFileURL ( file ) {
1336+ try {
1337+ var viewerOrigin = new URL ( window . location . href ) . origin || 'null' ;
1338+ if ( HOSTED_VIEWER_ORIGINS . indexOf ( viewerOrigin ) >= 0 ) {
1339+ // Hosted or local viewer, allow for any file locations
1340+ return ;
1341+ }
1342+ var fileOrigin = new URL ( file , window . location . href ) . origin ;
1343+ // Removing of the following line will not guarantee that the viewer will
1344+ // start accepting URLs from foreign origin -- CORS headers on the remote
1345+ // server must be properly configured.
1346+ if ( fileOrigin !== viewerOrigin ) {
1347+ throw new Error ( 'file origin does not match viewer\'s' ) ;
1348+ }
1349+ } catch ( e ) {
1350+ var message = e && e . message ;
1351+ var loadingErrorMessage = mozL10n . get ( 'loading_error' , null ,
1352+ 'An error occurred while loading the PDF.' ) ;
1353+
1354+ var moreInfo = {
1355+ message : message
1356+ } ;
1357+ PDFViewerApplication . error ( loadingErrorMessage , moreInfo ) ;
1358+ throw e ;
1359+ }
1360+ }
1361+ //#endif
1362+
13321363function webViewerLoad ( evt ) {
13331364 PDFViewerApplication . initialize ( ) . then ( webViewerInitialized ) ;
13341365}
@@ -1338,6 +1369,7 @@ function webViewerInitialized() {
13381369 var queryString = document . location . search . substring ( 1 ) ;
13391370 var params = parseQueryString ( queryString ) ;
13401371 var file = 'file' in params ? params . file : DEFAULT_URL ;
1372+ validateFileURL ( file ) ;
13411373//#endif
13421374//#if (FIREFOX || MOZCENTRAL)
13431375//var file = window.location.href.split('#')[0];
0 commit comments