فهرست منبع

Examples: Fix untrusted URL redirects.

Mugen87 4 سال پیش
والد
کامیت
2ef7b98f76
1فایلهای تغییر یافته به همراه13 افزوده شده و 2 حذف شده
  1. 13 2
      examples/index.html

+ 13 - 2
examples/index.html

@@ -58,6 +58,7 @@
 		const previewsToggler = document.getElementById( 'previewsToggler' );
 
 		const links = {};
+		const validRedirects = new Map();
 		const container = document.createElement( 'div' );
 
 		let selected = null;
@@ -87,14 +88,24 @@
 					container.appendChild( link );
 
 					links[ file ] = link;
+					validRedirects.set( file, file + '.html' );
 
 				}
 
 			}
 
-			if ( window.location.hash !== '' && links[ window.location.hash.substring( 1 ) ] ) {
+			if ( window.location.hash !== '' ) {
 
-				loadFile( window.location.hash.substring( 1 ) );
+				const file = window.location.hash.substring( 1 );
+
+				// use a predefined map of redirects to avoid untrusted URL redirection due to user-provided value
+
+				if ( validRedirects.has( file ) === true ) {
+
+					selectFile( file );
+					viewer.src = validRedirects.get( file );
+
+				}
 
 			}