feature: event origin whitelisting
This commit is contained in:
parent
aa31f53448
commit
b9e6b660a7
|
@ -2,15 +2,25 @@
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
const manifest = chrome.runtime.getManifest();
|
const manifest = chrome.runtime.getManifest();
|
||||||
|
const allowedOrigins = [
|
||||||
|
'https://openusercss.org',
|
||||||
|
'https://openusercss.com'
|
||||||
|
];
|
||||||
|
|
||||||
// Tell the page that we exist and that it should send the handshake
|
// Tell the page that we exist and that it should send the handshake
|
||||||
window.postMessage({
|
allowedOrigins.forEach(origin => {
|
||||||
'type': 'ouc-begin-handshake'
|
window.postMessage({
|
||||||
}, '*');
|
'type': 'ouc-begin-handshake'
|
||||||
|
}, origin);
|
||||||
|
});
|
||||||
|
|
||||||
// Wait for the handshake
|
// Wait for the handshake
|
||||||
window.addEventListener('message', event => {
|
window.addEventListener('message', event => {
|
||||||
if (event.data && event.data.type === 'ouc-handshake-question') {
|
if (
|
||||||
|
event.data
|
||||||
|
&& event.data.type === 'ouc-handshake-question'
|
||||||
|
&& allowedOrigins.includes(event.origin)
|
||||||
|
) {
|
||||||
// This is a representation of features that Stylus is capable of
|
// This is a representation of features that Stylus is capable of
|
||||||
const implementedFeatures = [
|
const implementedFeatures = [
|
||||||
'install-usercss',
|
'install-usercss',
|
||||||
|
@ -44,15 +54,16 @@
|
||||||
|
|
||||||
// We send the handshake response, which includes the key we got, plus some
|
// We send the handshake response, which includes the key we got, plus some
|
||||||
// additional metadata
|
// additional metadata
|
||||||
window.postMessage({
|
allowedOrigins.forEach(origin => {
|
||||||
'type': 'ouc-handshake-response',
|
window.postMessage({
|
||||||
'key': event.data.key,
|
'type': 'ouc-handshake-response',
|
||||||
'extension': {
|
'key': event.data.key,
|
||||||
'name': manifest.name,
|
'extension': {
|
||||||
'version': manifest.version,
|
'name': manifest.name,
|
||||||
'capabilities': reportedFeatures
|
'capabilities': reportedFeatures
|
||||||
}
|
}
|
||||||
}, '*');
|
}, origin);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user