0
我已阅读了如何在使用window.postMessage()
时避免安全问题 - 特别是MDN doc中的建议。关于window.postMessage()+ iframes +开发人员工具的安全问题
但是,由于所有预防性提示都是客户端,我无法理解如何阻止不良操作者从简单编辑更改其开发人员工具中的代码。
这是我正在处理的情况。我有一个包含嵌入式iframe的页面,并且我可以控制该iframe(它位于单独的域上,但提供它的供应商允许我将自定义JavaScript放入iframe源)。父窗口和iframe将来回通信。
/**
window at https://firstgoodorigin.com
Receives message from iframe to indicate
its contents have loaded.
Once that message has been received,
send a message back to the iframe.
*/
function handleMessage(message) {
if (message.origin === 'https://secondgoodorigin.com') {
// verify and sanitize what's in message.data
// (it'll be something like "loaded")
// if it's good, send a message back
message.source.postMessage('foo', 'https://secondgoodorigin.com');
}
}
window.addEventListener('message', handleMessage, false);
/**
iframe at https://secondgoodorigin.com
Tell parent window it has loaded. Once that happens
it will receive a message from the parent window, for
which we add an event listener.
*/
window.addEventListener('load',() => {
window.parent.postMessage('loaded', https://firstgoodorigin.com);
});
window.addEventListener('message', (message) => {
if (message.origin === 'https://firstgoodorigin.com') {
// verify and sanitize what's in message.data
// do stuff
}
});
鉴于这两个窗口源和iframe源将成为别人的Web检查内部编辑,什么是从消除所有的验证逻辑,并用恶意的东西取代它阻止他们?我在这里错过了什么?
要破解自己?一旦文件被浏览器下载,他们就可以在计算机上随心所欲地做任何事情。 – Will