Skip to content

fix(ui): exclude public static assets from auth middleware to fix image loading#6576

Open
an0nym21 wants to merge 2 commits into
keephq:mainfrom
an0nym21:fix/nextjs-image-optimization
Open

fix(ui): exclude public static assets from auth middleware to fix image loading#6576
an0nym21 wants to merge 2 commits into
keephq:mainfrom
an0nym21:fix/nextjs-image-optimization

Conversation

@an0nym21

Copy link
Copy Markdown
Contributor

Summary

Local images served via /_next/image were failing with "The requested resource isn't a valid image" in self-hosted deployments.

Root cause

When Next.js image optimization (/_next/image) fetches a local image internally via fetchInternalImage, the request goes through the full middleware pipeline. Public assets like /keep.png were not excluded from the middleware matcher, so the middleware redirected them to /signin — returning HTML instead of image data, which Next.js cannot process as an image.

keep.svg was already in the exclusion list but keep.png was not.

Fix

Add common static image extensions (.png, .jpg, .jpeg, .gif, .webp, .ico) to the middleware matcher negative lookahead so public assets bypass authentication entirely.

Test

Before: /_next/image?url=%2Fkeep.png&w=64&q=75 → "The requested resource isn't a valid image."
After: image loads correctly.

Fixes #6575

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. Bug Something isn't working UI User interface related issues labels Jun 11, 2026
an0nym21 added 2 commits June 12, 2026 09:22
…timization

Next.js standalone mode does not automatically include native modules in its
output trace. Without sharp, /_next/image returns "The requested resource
isn't a valid image" for all local images.
When Next.js image optimization (/_next/image) fetches a local image
internally via fetchInternalImage, the request goes through the Next.js
middleware pipeline. Public assets like /keep.png were not excluded from
the middleware matcher, causing them to be redirected to /signin — the
middleware received HTML instead of image data and returned
"The requested resource isn't a valid image."

Also reverts the Dockerfile sharp changes which were not the root cause
and bloated the image to over 1GB.
@an0nym21 an0nym21 force-pushed the fix/nextjs-image-optimization branch from 1201f98 to 68a1787 Compare June 12, 2026 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working size:XS This PR changes 0-9 lines, ignoring generated files. UI User interface related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: local images not loading — middleware redirects internal /_next/image fetches to signin

1 participant