Merge pull request #389 from alibaba/fix/ext-postmessage-source-guard
This commit is contained in:
@@ -46,6 +46,8 @@ async function exposeAgentToPage() {
|
||||
let multiPageAgent: InstanceType<typeof MultiPageAgent> | null = null
|
||||
|
||||
window.addEventListener('message', async (e) => {
|
||||
if (e.source !== window) return
|
||||
|
||||
const data = e.data
|
||||
if (typeof data !== 'object' || data === null) return
|
||||
if (data.channel !== 'PAGE_AGENT_EXT_REQUEST') return
|
||||
|
||||
@@ -45,6 +45,8 @@ export default defineUnlistedScript(() => {
|
||||
|
||||
const promise = new Promise<ExecutionResult>((resolve, reject) => {
|
||||
function handleMessage(e: MessageEvent) {
|
||||
if (e.source !== window) return
|
||||
|
||||
const data = e.data
|
||||
if (typeof data !== 'object' || data === null) return
|
||||
if (data.channel !== 'PAGE_AGENT_EXT_RESPONSE') return
|
||||
|
||||
Reference in New Issue
Block a user