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
7 changes: 7 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ export default defineNuxtConfig({
allowQuery: ['color', 'labelColor', 'label', 'name', 'style'],
},
},
'/api/registry/image-proxy': {
isr: {
expiration: 60 * 60 /* one hour */,
passQuery: true,
allowQuery: ['url', 'sig'],
},
},
'/api/registry/downloads/**': {
isr: {
expiration: 60 * 60 /* one hour */,
Expand Down
5 changes: 2 additions & 3 deletions server/api/registry/image-proxy/index.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ export default defineEventHandler(async event => {

const contentType = response.headers.get('content-type') || 'application/octet-stream'

// Only allow raster/vector image content types, but block SVG to prevent
// embedded JavaScript execution (SVGs can contain <script> tags, event handlers, etc.)
if (!contentType.startsWith('image/') || contentType.includes('svg')) {
// Allow raster/vector image content types (we don't inject external content into DOM, so SVG is allowed too)
if (!contentType.startsWith('image/')) {
await response.body?.cancel()
throw createError({
statusCode: 400,
Expand Down
13 changes: 13 additions & 0 deletions server/utils/image-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ const TRUSTED_IMAGE_DOMAINS = [
'repository-images.githubusercontent.com',
'github.githubassets.com',
'objects.githubusercontent.com',
'avatars2.githubusercontent.com',
'cloud.githubusercontent.com',

// GitLab
'gitlab.com',

// CDNs commonly used in READMEs
'cdn.jsdelivr.net',
'data.jsdelivr.com',
'unpkg.com',

// Well-known badge/shield services
Expand All @@ -63,6 +66,16 @@ const TRUSTED_IMAGE_DOMAINS = [
'api.codeclimate.com',
'bundlephobia.com',
'packagephobia.com',
'deepwiki.com',
'saucelabs.github.io',
'opencollective.com',
'circleci.com',
'www.codetriage.com',
'badges.gitter.im',
'nodei.co',
'travis-ci.org',
'secure.travis-ci.org',
'img.badgesize.io',
]

/**
Expand Down
Loading