Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
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
13 changes: 10 additions & 3 deletions 13 server/api/registry/image-proxy/index.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,17 @@ export default defineEventHandler(async event => {
})
}

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

const rawContentType = response.headers.get('content-type') || 'application/octet-stream'
const contentType = rawContentType.split(';', 1)[0]?.trim().toLowerCase()

const imagePathname = new URL(url).pathname.toLowerCase()
// Since some services don't specify the content-type, leaving it up to the user, we additionally check the extension.
// This doesn't compromise security, as both the extension and the content-type allow the user to forge the value.
const isImageLike =
contentType === 'application/octet-stream' &&
['.png', '.jpg', '.jpeg', '.gif'].some(ext => imagePathname.endsWith(ext))
// Allow raster/vector image content types (we don't inject external content into DOM, so SVG is allowed too)
if (!contentType.startsWith('image/')) {
if (!contentType?.startsWith('image/') && !isImageLike) {
await response.body?.cancel()
throw createError({
statusCode: 400,
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.