Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

test(markdown-editor): cover isSafeImageSrc image-src allowlist

Sergey Kozyrenko3004d94226a9
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-image-src.test.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-image-src.test.ts
new file mode 100644
index 00000000..8e1fc1ce
--- /dev/null
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-image-src.test.ts
@@ -0,0 +1,29 @@
+import { describe, expect, it } from 'vitest';
+
+import { isSafeImageSrc } from './markdown-editor';
+
+// The Image extension stores whatever src it is handed; isSafeImageSrc is the allowlist that blocks dangerous
+// PROTOCOLS (javascript:, data:text/html, vbscript:, file:) before a src is saved. A bare relative string
+// resolves against the page origin (http/https) and is intentionally allowed — the guard validates the
+// protocol, not that the URL is absolute.
+describe('isSafeImageSrc — image-src protocol allowlist', () => {
+ it.each([
+ 'http://example.com/a.png',
+ 'https://example.com/a.png',
+ 'data:image/png;base64,AAAA',
+ 'data:image/svg+xml;utf8,<svg/>',
+ ])('allows %s', (url) => {
+ expect(isSafeImageSrc(url)).toBe(true);
+ });
+
+ it.each([
+ 'javascript:alert(1)',
+ 'data:text/html,<script>alert(1)</script>',
+ 'data:application/pdf;base64,AA',
+ 'vbscript:msgbox(1)',
+ 'file:///etc/passwd',
+ 'http://', // malformed → URL constructor throws → rejected via the catch
+ ])('rejects %s', (url) => {
+ expect(isSafeImageSrc(url)).toBe(false);
+ });
+});
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor.tsx b/frontend/src/components/shared/markdown-editor/markdown-editor.tsx
index 3058a8da..da4b413c 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor.tsx
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor.tsx
@@ -303,7 +303,7 @@ function MarkdownEditor({
// The Image extension (unlike Link) doesn't validate the src protocol, so reject non-http(s)/non-image-data
// URLs (javascript:, data:text/html, …) before they're stored — defense-in-depth for saved content.
-const isSafeImageSrc = (url: string): boolean => {
+export const isSafeImageSrc = (url: string): boolean => {
try {
const { protocol } = new URL(url, window.location.href);