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
5 changes: 5 additions & 0 deletions app/components/Readme.vue
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,11 @@ function handleClick(event: MouseEvent) {
z-index: 1;
}

/* With defined width, height will be automatically calculated using the aspect ratio */
.readme :deep(img[width]) {
height: auto;
}

.readme :deep(video) {
height: revert-layer;
display: revert-layer;
Expand Down
10 changes: 5 additions & 5 deletions server/utils/image-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export const TRUSTED_IMAGE_DOMAINS = [
'npmx.dev',

// GitHub (already proxied by GitHub's own camo)
// We do not include github.com and user-images.githubusercontent.com because they
// might return redirects to s3 which will be blocked by the CSP
'raw.githubusercontent.com',
'github.com',
'user-images.githubusercontent.com',
'avatars.githubusercontent.com',
'repository-images.githubusercontent.com',
'github.githubassets.com',
Expand Down Expand Up @@ -69,6 +69,7 @@ export const TRUSTED_IMAGE_DOMAINS = [
'deepwiki.com',
'saucelabs.github.io',
'opencollective.com',
'images.opencollective.com',
'circleci.com',
'www.codetriage.com',
'badges.gitter.im',
Expand All @@ -86,9 +87,8 @@ export function isTrustedImageDomain(url: string): boolean {
if (!parsed?.hostname) return false

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

/**
Expand Down
12 changes: 3 additions & 9 deletions test/unit/server/utils/image-proxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ describe('Image Proxy Utils', () => {
).toBe(true)
})

it('trusts GitHub user images', () => {
expect(isTrustedImageDomain('https://user-images.githubusercontent.com/123/image.png')).toBe(
true,
)
})

it('trusts shields.io badge URLs', () => {
expect(isTrustedImageDomain('https://img.shields.io/badge/test-passing-green')).toBe(true)
})
Expand All @@ -36,8 +30,8 @@ describe('Image Proxy Utils', () => {
expect(isTrustedImageDomain('https://npmx.dev/images/logo.png')).toBe(true)
})

it('trusts subdomain of trusted domains', () => {
expect(isTrustedImageDomain('https://sub.gitlab.com/image.png')).toBe(true)
it('does not trust subdomain of trusted domains', () => {
expect(isTrustedImageDomain('https://sub.gitlab.com/image.png')).toBe(false)
})

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

it('does not proxy GitHub blob URLs', () => {
const url = 'https://github.com/owner/repo/blob/main/assets/logo.png'
const url = 'https://cloud.githubusercontent.com/assets/123/logo.png'
expect(toProxiedImageUrl(url, TEST_SECRET)).toBe(url)
})
Comment thread
alexdln marked this conversation as resolved.

Expand Down
Loading