mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(editor): Return early in ws message handler if no 'command' keyword is found (#7946)
## Summary Avoid processing websocket messages not n8n sent (filter on 'command' keyword)
This commit is contained in:
parent
dcf12867b3
commit
5b2defc867
|
@ -136,7 +136,9 @@ const onMouseLeave = () => {
|
|||
};
|
||||
|
||||
const receiveMessage = ({ data }: MessageEvent) => {
|
||||
if (data?.includes('"command"')) {
|
||||
if (!data?.includes?.('"command"')) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const json = JSON.parse(data);
|
||||
if (json.command === 'n8nReady') {
|
||||
|
@ -151,7 +153,6 @@ const receiveMessage = ({ data }: MessageEvent) => {
|
|||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
const onDocumentScroll = () => {
|
||||
if (insideIframe.value) {
|
||||
|
|
|
@ -247,4 +247,18 @@ describe('WorkflowPreview', () => {
|
|||
expect(emitted()).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
it('should not do anything if no "command" is sent in the message and the `includes` method cannot be applied to the data', async () => {
|
||||
const { emitted } = renderComponent({
|
||||
pinia,
|
||||
props: {},
|
||||
});
|
||||
|
||||
window.postMessage(null, '*');
|
||||
|
||||
await waitFor(() => {
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
expect(emitted()).toEqual({});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4312,7 +4312,9 @@ export default defineComponent({
|
|||
}
|
||||
},
|
||||
async onPostMessageReceived(message: MessageEvent) {
|
||||
if (message?.data?.includes('"command"')) {
|
||||
if (!message?.data?.includes?.('"command"')) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const json = JSON.parse(message.data);
|
||||
if (json && json.command === 'openWorkflow') {
|
||||
|
@ -4363,7 +4365,6 @@ export default defineComponent({
|
|||
this.workflowsStore.activeWorkflowExecution = json.execution;
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
},
|
||||
async onImportWorkflowDataEvent(data: IDataObject) {
|
||||
await this.importWorkflowData(data.data as IWorkflowDataUpdate, 'file');
|
||||
|
|
Loading…
Reference in a new issue