fix(ext): guard postMessage listeners against iframe sources
Add `e.source !== window` check to both content script and main-world script message handlers, preventing iframes from injecting or intercepting extension bridge messages.
This commit is contained in:
@@ -46,6 +46,8 @@ async function exposeAgentToPage() {
|
|||||||
let multiPageAgent: InstanceType<typeof MultiPageAgent> | null = null
|
let multiPageAgent: InstanceType<typeof MultiPageAgent> | null = null
|
||||||
|
|
||||||
window.addEventListener('message', async (e) => {
|
window.addEventListener('message', async (e) => {
|
||||||
|
if (e.source !== window) return
|
||||||
|
|
||||||
const data = e.data
|
const data = e.data
|
||||||
if (typeof data !== 'object' || data === null) return
|
if (typeof data !== 'object' || data === null) return
|
||||||
if (data.channel !== 'PAGE_AGENT_EXT_REQUEST') return
|
if (data.channel !== 'PAGE_AGENT_EXT_REQUEST') return
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ export default defineUnlistedScript(() => {
|
|||||||
|
|
||||||
const promise = new Promise<ExecutionResult>((resolve, reject) => {
|
const promise = new Promise<ExecutionResult>((resolve, reject) => {
|
||||||
function handleMessage(e: MessageEvent) {
|
function handleMessage(e: MessageEvent) {
|
||||||
|
if (e.source !== window) return
|
||||||
|
|
||||||
const data = e.data
|
const data = e.data
|
||||||
if (typeof data !== 'object' || data === null) return
|
if (typeof data !== 'object' || data === null) return
|
||||||
if (data.channel !== 'PAGE_AGENT_EXT_RESPONSE') return
|
if (data.channel !== 'PAGE_AGENT_EXT_RESPONSE') return
|
||||||
|
|||||||
Reference in New Issue
Block a user