Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 3dd749c

Browse files
committed
Fix XSS in goToHome
1 parent a0f5b73 commit 3dd749c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

google-codelab.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ <h2>Would you like to resume where you left off?</h2>
427427
},
428428

429429
_goToHome: function () {
430+
// extract 'index' search param
430431
var index;
431432
var parts = location.search.substring(1).split('&');
432433
for (var i = 0; i < parts.length; i++) {
@@ -436,13 +437,15 @@ <h2>Would you like to resume where you left off?</h2>
436437
break;
437438
}
438439
}
439-
440-
var returnToIndex = index ? decodeURIComponent(index) : index;
441-
if (!returnToIndex || returnToIndex.slice(-6) === '/index') {
442-
returnToIndex = '/';
440+
// decode and extract index name from the search param
441+
// default index is 'index'
442+
index = index ? decodeURIComponent(index) : '';
443+
index = index.replace(/[^a-z0-9\-]+/ig, '');
444+
if (index === 'index') {
445+
index = '';
443446
}
444-
445-
window.location.href = returnToIndex;
447+
// navigate away to the index page
448+
window.location.href = '/' + index;
446449
},
447450

448451
_tocItemClass: function(selected, i) {

0 commit comments

Comments
 (0)