Skip to content

Commit

Permalink
feat: prevent url injection
Browse files Browse the repository at this point in the history
  • Loading branch information
r00gm committed Sep 20, 2024
1 parent 48294e7 commit 180fc4b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,13 @@ describe('useClipboard()', () => {
await userEvent.paste(unsafeHtml);
expect(within(getByTestId('xss-attack')).queryByRole('img')).not.toBeInTheDocument();
});

it('sanitizes URL with HTML tags', async () => {
// eslint-disable-next-line n8n-local-rules/no-unneeded-backticks
const unsafeURL = `https://www.ex.com/sfefdfd<details title='"><details title=&#39;&quot;><img/src/onerror=alert(document.domain)>/&#39;>'>/c.json`;
const { getByTestId } = render(TestComponent);

await userEvent.paste(unsafeURL);
expect(getByTestId('xss-attack').innerHTML).toBe('https://www.ex.com/sfefdfd/c.json');
});
});
4 changes: 2 additions & 2 deletions packages/editor-ui/src/composables/useClipboard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { onBeforeUnmount, onMounted, ref } from 'vue';
import { useClipboard as useClipboardCore } from '@vueuse/core';
import { useDebounce } from '@/composables/useDebounce';
import { sanitizeIfString } from '@/utils/htmlUtils';
import sanitize from 'sanitize-html';

type ClipboardEventFn = (data: string, event?: ClipboardEvent) => void;

Expand Down Expand Up @@ -43,7 +43,7 @@ export function useClipboard(

const clipboardData = event.clipboardData;
if (clipboardData !== null) {
const clipboardValue = sanitizeIfString(clipboardData.getData('text/plain'));
const clipboardValue = sanitize(clipboardData.getData('text/plain'));
onPasteCallback.value(clipboardValue, event);
}
}
Expand Down

0 comments on commit 180fc4b

Please sign in to comment.