Skip to content

Commit

Permalink
use v-n8n-html to render html error message
Browse files Browse the repository at this point in the history
  • Loading branch information
igatanasov committed Nov 19, 2024
1 parent a981fa3 commit 8bc5269
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ describe('NodeExecutionErrorMessage', () => {
});

it('sanitizes malicious script in error message', () => {
const { container } = renderComponent({
const { getByTestId } = renderComponent({
props: {
nodeName: 'Test Node',
errorMessage: '<img src=x onerror=alert(1)>',
},
});
expect(container.querySelector('img')).not.toBeInTheDocument();
expect(getByTestId('sanitized-error-message')).toContainHTML('<img src="x">');
});

it('sanitizes malicious script in error message with nested tags', () => {
const { container } = renderComponent({
const { getByTestId } = renderComponent({
props: {
nodeName: 'Test Node',
errorMessage: '<div><img src=x onerror=alert(1)></div>',
},
});
expect(container.querySelector('img')).not.toBeInTheDocument();
expect(getByTestId('sanitized-error-message')).toContainHTML('<div><img src="x"></div>');
});

it('sanitizes malicious script in error message with script tag', () => {
Expand Down
12 changes: 2 additions & 10 deletions packages/editor-ui/src/components/NodeExecutionErrorMessage.vue
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
<script lang="ts" setup>
/* eslint-disable vue/no-v-html */
import { useI18n } from '@/composables/useI18n';
import { sanitizeHtml } from '@/utils/htmlUtils';
import { computed } from 'vue';
const i18n = useI18n();
const props = defineProps<{
defineProps<{
nodeName: string;
errorMessage?: string;
}>();
const sanitizedErrorMessage = computed(() => {
return props.errorMessage ? sanitizeHtml(props.errorMessage) : '';
});
</script>

<template>
<div>
<span data-test-id="sanitized-error-message" v-html="sanitizedErrorMessage"></span>
<span v-n8n-html="errorMessage" data-test-id="sanitized-error-message"></span>
<br />
<a data-action="openNodeDetail" :data-action-parameter-node="nodeName">{{
i18n.baseText('node.executionError.openNode')
Expand Down

0 comments on commit 8bc5269

Please sign in to comment.