Check origin on window messages
This commit is contained in:
parent
2ace8d4ffa
commit
aee16c4431
@ -27,6 +27,7 @@ class SettingsPopupPreview {
|
||||
this.popupShown = false;
|
||||
this.themeChangeTimeout = null;
|
||||
this.textSource = null;
|
||||
this._targetOrigin = chrome.runtime.getURL('/').replace(/\/$/, '');
|
||||
}
|
||||
|
||||
static create() {
|
||||
@ -97,6 +98,8 @@ class SettingsPopupPreview {
|
||||
}
|
||||
|
||||
onMessage(e) {
|
||||
if (e.origin !== this._targetOrigin) { return; }
|
||||
|
||||
const {action, params} = e.data;
|
||||
const handler = SettingsPopupPreview._messageHandlers.get(action);
|
||||
if (typeof handler !== 'function') { return; }
|
||||
|
@ -40,20 +40,22 @@ function showAppearancePreview() {
|
||||
|
||||
window.wanakana.bind(text[0]);
|
||||
|
||||
const targetOrigin = chrome.runtime.getURL('/').replace(/\/$/, '');
|
||||
|
||||
text.on('input', () => {
|
||||
const action = 'setText';
|
||||
const params = {text: text.val()};
|
||||
frame.contentWindow.postMessage({action, params}, '*');
|
||||
frame.contentWindow.postMessage({action, params}, targetOrigin);
|
||||
});
|
||||
customCss.on('input', () => {
|
||||
const action = 'setCustomCss';
|
||||
const params = {css: customCss.val()};
|
||||
frame.contentWindow.postMessage({action, params}, '*');
|
||||
frame.contentWindow.postMessage({action, params}, targetOrigin);
|
||||
});
|
||||
customOuterCss.on('input', () => {
|
||||
const action = 'setCustomOuterCss';
|
||||
const params = {css: customOuterCss.val()};
|
||||
frame.contentWindow.postMessage({action, params}, '*');
|
||||
frame.contentWindow.postMessage({action, params}, targetOrigin);
|
||||
});
|
||||
|
||||
container.append(frame);
|
||||
|
@ -33,6 +33,7 @@ class Popup {
|
||||
this._options = null;
|
||||
this._contentScale = 1.0;
|
||||
this._containerSizeContentScale = null;
|
||||
this._targetOrigin = chrome.runtime.getURL('/').replace(/\/$/, '');
|
||||
|
||||
this._container = document.createElement('iframe');
|
||||
this._container.className = 'yomichan-float';
|
||||
@ -349,7 +350,7 @@ class Popup {
|
||||
|
||||
_invokeApi(action, params={}) {
|
||||
if (this._container.contentWindow) {
|
||||
this._container.contentWindow.postMessage({action, params}, '*');
|
||||
this._container.contentWindow.postMessage({action, params}, this._targetOrigin);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user