Skip to content

Commit 03c9d1c

Browse files
Potential fix for code scanning alert no. 18: Incomplete URL substring sanitization
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent ccda0da commit 03c9d1c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/components/imageLightbox/imageLightbox.spec.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ import {isAllowedRemoteImage, isExternalImage} from 'sentry-docs/config/images';
66
// Mock image config functions
77
vi.mock('sentry-docs/config/images', () => ({
88
isExternalImage: vi.fn((src: string) => src.startsWith('http') || src.startsWith('//')),
9-
isAllowedRemoteImage: vi.fn((src: string) => src.includes('allowed-domain.com')),
9+
isAllowedRemoteImage: vi.fn((src: string) => {
10+
try {
11+
// Handle protocol-relative URLs
12+
const url = src.startsWith('//') ? new URL('https:' + src) : new URL(src);
13+
return url.hostname === 'allowed-domain.com';
14+
} catch {
15+
return false;
16+
}
17+
}),
1018
}));
1119

1220
const shouldUseNextImage = (width?: number, height?: number, src?: string) => {

0 commit comments

Comments
 (0)