Skip to content

Commit 1fcb2d8

Browse files
authored
Merge pull request #1538 from RedYetiDev/patch-2
Update frames.erb for better XSS check
2 parents 3059017 + a831a59 commit 1fcb2d8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

templates/default/fulldoc/html/frames.erb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
<title><%= options.title %></title>
66
</head>
77
<script type="text/javascript">
8-
var match = decodeURIComponent(window.location.hash).match(/^#!(.+)/);
9-
var name = match ? match[1] : '<%= url_for_main %>';
10-
name = name.replace(/^((\w*):)?[\/\\]*/gm, '').trim();
11-
window.top.location.replace(name)
8+
var mainUrl = '<%= url_for_main %>';
9+
try {
10+
var match = decodeURIComponent(window.location.hash).match(/^#!(.+)/);
11+
var name = match ? match[1] : mainUrl;
12+
var url = new URL(name, location.href);
13+
window.top.location.replace(url.origin === location.origin ? name : mainUrl);
14+
} catch (e) {
15+
window.top.location.replace(mainUrl);
16+
}
1217
</script>
1318
<noscript>
1419
<h1>Oops!</h1>

0 commit comments

Comments
 (0)