mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-04-07 14:04:35 +08:00
[feature] Avoid wildcard origin in postMessage
This commit is contained in:
@ -23,7 +23,7 @@ let settingsButton = null;
|
|||||||
function sendMessageToFrame(iframeId, data) {
|
function sendMessageToFrame(iframeId, data) {
|
||||||
const frame = document.getElementById(iframeId);
|
const frame = document.getElementById(iframeId);
|
||||||
if (frame) {
|
if (frame) {
|
||||||
frame.contentWindow.postMessage(JSON.stringify(data), '*');
|
frame.contentWindow.postMessage(JSON.stringify(data), window.location.origin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,6 +32,11 @@ function sendMessageToFrame(iframeId, data) {
|
|||||||
* @param {MessageEvent} event - The message event
|
* @param {MessageEvent} event - The message event
|
||||||
*/
|
*/
|
||||||
function receiveMessage(event) {
|
function receiveMessage(event) {
|
||||||
|
if (event.origin !== window.location.origin) {
|
||||||
|
console.warn('Rejected postMessage from untrusted origin:', event.origin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof event.data !== 'string') {
|
if (typeof event.data !== 'string') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user