Skip to content

OG image endpoint crashes on invalid type query parameter #9

Description

@tokiory

Problem

src/routes/api/ogimg/+server.ts casts the type query parameter to keyof typeof IMAGE_SIZE without validating it:

const type = (url.searchParams.get('type') || 'opengraph') as keyof typeof IMAGE_SIZE;

A request such as /api/ogimg?type=bad makes IMAGE_SIZE[type] undefined. The endpoint then dereferences .upscale, .width, and .height, causing a runtime error.

Impact

Malformed requests can return a 500 from the OG image endpoint.

Expected

Unknown type values should either fall back to opengraph or return a controlled 400 response.

Suggested Fix

Validate type against IMAGE_SIZE before using it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions