Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/studio/views/chat-subcomponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export const MessageList = ({
)
},
img: ({ src, alt }) => {
const safeSrc = typeof src === 'string' && src ? sanitizeUrl(src) : ''
const safeSrc = typeof src === 'string' && src ? sanitizeUrl(src, ['http:', 'https:']) : ''
if (!safeSrc) return null
return <img src={safeSrc} alt={alt ?? ''} />
},
Expand Down
5 changes: 5 additions & 0 deletions src/components/studio/views/editor-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export const EditorPreview = ({ content }: { content: string }) => (
</a>
)
},
img: ({ src, alt }) => {
const safeSrc = typeof src === 'string' && src ? sanitizeUrl(src, ['http:', 'https:']) : ''
if (!safeSrc) return null
return <img src={safeSrc} alt={alt ?? ''} />
},
}}
>
{content || '_Nothing to preview._'}
Expand Down
8 changes: 8 additions & 0 deletions src/lib/security.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ describe('sanitizeUrl', () => {
expect(sanitizeUrl('https://example.com', ['ftp'])).toBe('')
})

it('restricts image source protocols when explicit http/https allowlist is passed', () => {
const imageProtocols = ['http:', 'https:']
expect(sanitizeUrl('https://example.com/image.png', imageProtocols)).toBe('https://example.com/image.png')
expect(sanitizeUrl('http://example.com/image.png', imageProtocols)).toBe('http://example.com/image.png')
expect(sanitizeUrl('mailto:user@example.com', imageProtocols)).toBe('')
expect(sanitizeUrl('tel:+1234567890', imageProtocols)).toBe('')
})

it('strips ASCII control characters and neutralizes obfuscated scheme payloads', () => {
expect(sanitizeUrl('/dashboard\x00path')).toBe('/dashboardpath')
expect(sanitizeUrl('/docs\x09setup')).toBe('/docssetup')
Expand Down
Loading