fix(ui): exclude public static assets from auth middleware to fix image loading#6576
Open
an0nym21 wants to merge 2 commits into
Open
fix(ui): exclude public static assets from auth middleware to fix image loading#6576an0nym21 wants to merge 2 commits into
an0nym21 wants to merge 2 commits into
Conversation
…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.
1201f98 to
68a1787
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Local images served via
/_next/imagewere 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 viafetchInternalImage, the request goes through the full middleware pipeline. Public assets like/keep.pngwere 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.svgwas already in the exclusion list butkeep.pngwas 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