Skip to content

Commit 57ed389

Browse files
authored
fix: update trusted images policies (#2622)
1 parent 4c38a7d commit 57ed389

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

app/components/Readme.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,11 @@ function handleClick(event: MouseEvent) {
444444
z-index: 1;
445445
}
446446
447+
/* With defined width, height will be automatically calculated using the aspect ratio */
448+
.readme :deep(img[width]) {
449+
height: auto;
450+
}
451+
447452
.readme :deep(video) {
448453
height: revert-layer;
449454
display: revert-layer;

server/utils/image-proxy.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export const TRUSTED_IMAGE_DOMAINS = [
3434
'npmx.dev',
3535

3636
// GitHub (already proxied by GitHub's own camo)
37+
// We do not include github.com and user-images.githubusercontent.com because they
38+
// might return redirects to s3 which will be blocked by the CSP
3739
'raw.githubusercontent.com',
38-
'github.com',
39-
'user-images.githubusercontent.com',
4040
'avatars.githubusercontent.com',
4141
'repository-images.githubusercontent.com',
4242
'github.githubassets.com',
@@ -69,6 +69,7 @@ export const TRUSTED_IMAGE_DOMAINS = [
6969
'deepwiki.com',
7070
'saucelabs.github.io',
7171
'opencollective.com',
72+
'images.opencollective.com',
7273
'circleci.com',
7374
'www.codetriage.com',
7475
'badges.gitter.im',
@@ -86,9 +87,8 @@ export function isTrustedImageDomain(url: string): boolean {
8687
if (!parsed?.hostname) return false
8788

8889
const hostname = parsed.hostname.toLowerCase()
89-
return TRUSTED_IMAGE_DOMAINS.some(
90-
domain => hostname === domain || hostname.endsWith(`.${domain}`),
91-
)
90+
// We only look at exact matches (not subdomains), since the same array is used as a check in CSP
91+
return TRUSTED_IMAGE_DOMAINS.includes(hostname)
9292
}
9393

9494
/**

test/unit/server/utils/image-proxy.spec.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ describe('Image Proxy Utils', () => {
1818
).toBe(true)
1919
})
2020

21-
it('trusts GitHub user images', () => {
22-
expect(isTrustedImageDomain('https://user-images.githubusercontent.com/123/image.png')).toBe(
23-
true,
24-
)
25-
})
26-
2721
it('trusts shields.io badge URLs', () => {
2822
expect(isTrustedImageDomain('https://img.shields.io/badge/test-passing-green')).toBe(true)
2923
})
@@ -36,8 +30,8 @@ describe('Image Proxy Utils', () => {
3630
expect(isTrustedImageDomain('https://npmx.dev/images/logo.png')).toBe(true)
3731
})
3832

39-
it('trusts subdomain of trusted domains', () => {
40-
expect(isTrustedImageDomain('https://sub.gitlab.com/image.png')).toBe(true)
33+
it('does not trust subdomain of trusted domains', () => {
34+
expect(isTrustedImageDomain('https://sub.gitlab.com/image.png')).toBe(false)
4135
})
4236

4337
it('does not trust arbitrary domains', () => {
@@ -265,7 +259,7 @@ describe('Image Proxy Utils', () => {
265259
})
266260

267261
it('does not proxy GitHub blob URLs', () => {
268-
const url = 'https://github.com/owner/repo/blob/main/assets/logo.png'
262+
const url = 'https://cloud.githubusercontent.com/assets/123/logo.png'
269263
expect(toProxiedImageUrl(url, TEST_SECRET)).toBe(url)
270264
})
271265

0 commit comments

Comments
 (0)