Skip to content

Commit

Permalink
fix(editor): Fixing XSS vulnerability in toast messages (#10329)
Browse files Browse the repository at this point in the history
Co-authored-by: Adi <aditya@netroy.in>
  • Loading branch information
MiloradFilipovic and netroy authored Aug 8, 2024
1 parent b6c47c0 commit 38bdd9f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions packages/editor-ui/src/components/NpsSurvey.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ async function send() {
message: Number(form.value.value) >= 8 ? i18n.baseText('prompts.npsSurvey.reviewUs') : '',
type: 'success',
duration: 15000,
dangerouslyUseHTMLString: true,
});
setTimeout(() => {
Expand Down
3 changes: 2 additions & 1 deletion packages/editor-ui/src/composables/useExecutionDebugging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useUIStore } from '@/stores/ui.store';
import { useTelemetry } from './useTelemetry';
import { useRootStore } from '@/stores/root.store';
import { isFullExecutionResponse } from '@/utils/typeGuards';
import { sanitizeHtml } from '@/utils/htmlUtils';

export const useExecutionDebugging = () => {
const telemetry = useTelemetry();
Expand Down Expand Up @@ -61,7 +62,7 @@ export const useExecutionDebugging = () => {
h(
'ul',
{ class: 'mt-l ml-l' },
matchingPinnedNodeNames.map((name) => h('li', name)),
matchingPinnedNodeNames.map((name) => h('li', sanitizeHtml(name))),
),
]);

Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/composables/usePushConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ export function usePushConnection({ router }: { router: ReturnType<typeof useRou
message: `${action} <a href="https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.wait/" target="_blank">More info</a>`,
type: 'success',
duration: 0,
dangerouslyUseHTMLString: true,
});
} else if (runDataExecuted.finished !== true) {
titleChange.titleSet(workflow.name as string, 'ERROR');
Expand Down Expand Up @@ -438,7 +439,6 @@ export function usePushConnection({ router }: { router: ReturnType<typeof useRou
message: runDataExecutedErrorMessage,
type: 'error',
duration: 0,
dangerouslyUseHTMLString: true,
});
}
}
Expand Down
35 changes: 18 additions & 17 deletions packages/editor-ui/src/composables/useToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface NotificationErrorWithNodeAndDescription extends ApplicationErro
}

const messageDefaults: Partial<Omit<NotificationOptions, 'message'>> = {
dangerouslyUseHTMLString: true,
dangerouslyUseHTMLString: false,
position: 'bottom-right',
};

Expand All @@ -32,28 +32,28 @@ export function useToast() {
const i18n = useI18n();

function showMessage(messageData: Partial<NotificationOptions>, track = true) {
messageData = { ...messageDefaults, ...messageData };

Object.defineProperty(messageData, 'message', {
value:
typeof messageData.message === 'string'
? sanitizeHtml(messageData.message)
: messageData.message,
writable: true,
enumerable: true,
});
const { message, title } = messageData;
const params = { ...messageDefaults, ...messageData };

if (typeof message === 'string') {
params.message = sanitizeHtml(message);
}

if (typeof title === 'string') {
params.title = sanitizeHtml(title);
}

const notification = Notification(messageData);
const notification = Notification(params);

if (messageData.duration === 0) {
if (params.duration === 0) {
stickyNotificationQueue.push(notification);
}

if (messageData.type === 'error' && track) {
if (params.type === 'error' && track) {
telemetry.track('Instance FE emitted error', {
error_title: messageData.title,
error_message: messageData.message,
caused_by_credential: causedByCredential(messageData.message as string),
error_title: params.title,
error_message: params.message,
caused_by_credential: causedByCredential(params.message as string),
workflow_id: workflowsStore.workflowId,
});
}
Expand Down Expand Up @@ -133,6 +133,7 @@ export function useToast() {
${collapsableDetails(error)}`,
type: 'error',
duration: 0,
dangerouslyUseHTMLString: true,
},
false,
);
Expand Down
4 changes: 4 additions & 0 deletions packages/editor-ui/src/utils/htmlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export function sanitizeHtml(dirtyHtml: string) {
}

if (ALLOWED_HTML_ATTRIBUTES.includes(name) || name.startsWith('data-')) {
// href is allowed but we need to sanitize certain protocols
if (name === 'href' && !value.match(/^https?:\/\//gm)) {
return '';
}
return `${name}="${friendlyAttrValue(value)}"`;
}

Expand Down

0 comments on commit 38bdd9f

Please sign in to comment.