Skip to content

Commit c069ce4

Browse files
authored
Merge pull request #101 from AI-Tournaments/patch
Added `isURLSecure`.
2 parents 3a2f395 + 5289069 commit c069ce4

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

Replay/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ function a(){
278278
document.body.removeChild(element);
279279
});
280280
}
281+
function isURLSecure(url){
282+
const anchor = document.createElement('a');
283+
anchor.href = url;
284+
return anchor.host === window.location.host;
285+
};
281286
document.getElementById('load-previous-replay').addEventListener('click', ()=>{
282287
refreshStoredReplays();
283288
_element_control.classList.add('hidden');
@@ -436,11 +441,7 @@ function a(){
436441
}
437442
let url = option.value;
438443
const session = GitHubApi.getSessionStorage();
439-
let secureUrl = url.startsWith('https://ai-tournaments.github.io/');
440-
if(!secureUrl){
441-
const u = url.replace('//', '');
442-
secureUrl = u.indexOf('/') < u.indexOf('.');
443-
}
444+
let secureUrl = isURLSecure(url);
444445
if(!secureUrl && !session?.externalReplaysAccepted){
445446
const passphrase = 'I accept external replay viewers';
446447
session.externalReplaysAccepted = (prompt('External replays are by default blocked for security reasons, since they are outside of AI-Tournaments control. So use them at your own risk. Only do this to URLs for code that you trust.\n\nWrite "'+passphrase+'" to allow external replay viewers.')??'').toLowerCase() === passphrase.toLowerCase();

0 commit comments

Comments
 (0)