@@ -1329,6 +1329,37 @@ window.PDFView = PDFViewerApplication; // obsolete name, using it as an alias
1329
1329
//})();
1330
1330
//#endif
1331
1331
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
+
1332
1363
function webViewerLoad ( evt ) {
1333
1364
PDFViewerApplication . initialize ( ) . then ( webViewerInitialized ) ;
1334
1365
}
@@ -1338,6 +1369,7 @@ function webViewerInitialized() {
1338
1369
var queryString = document . location . search . substring ( 1 ) ;
1339
1370
var params = parseQueryString ( queryString ) ;
1340
1371
var file = 'file' in params ? params . file : DEFAULT_URL ;
1372
+ validateFileURL ( file ) ;
1341
1373
//#endif
1342
1374
//#if (FIREFOX || MOZCENTRAL)
1343
1375
//var file = window.location.href.split('#')[0];
0 commit comments