fix(client): prevent go to local links in preview

pull/35211/head
Valeriy S 2019-02-13 09:37:45 +03:00 committed by mrugesh mohapatra
parent d13cb03810
commit a4dafdf54f
1 changed files with 18 additions and 0 deletions

View File

@ -25,6 +25,24 @@ const createHeader = (id = mainId) => `
window.__err = err;
return true;
};
document.addEventListener('click', function(e) {
let element = e.target;
while(element && element.nodeName !== 'A') {
element = element.parentElement;
}
if (element) {
const href = element.getAttribute('href');
if (!href || href[0] !== '#' && !href.match(/^https?:\\/\\//)) {
e.preventDefault();
}
}
}, false);
document.addEventListener('submit', function(e) {
const action = e.target.getAttribute('action');
if (!action || !action.match(/https?:\\/\\//)) {
e.preventDefault();
}
}, false);
</script>
`;