-
Notifications
You must be signed in to change notification settings - Fork 27.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Middleware can't detect image requests #68217
Comments
Can you provide more info regarding what you actually want to do? |
No reference needed, middleware should be able to detect and intercept before image optimization work. |
Alright, so the problem seems to come from here, finished = await this.normalizeAndAttachMetadata(req, res, parsedUrl)
if (finished) return
finished = await this.handleCatchallMiddlewareRequest( // We never arrive here for `/_next/image` This call, returns finished true, and then the middleware is never run for I wonder, if, through some code refactor, the case where |
Ok, I think I have a fix, PR coming up! |
Thanks @icyJoseph |
I'm still investigating. Though in that PR the fix - works... I'm not sure about it. I'm also adding a test to prevent this regressing again. It would be good to narrow down which version introduced this.. 🤔 |
I'm not so sure either, I didn't realize it until I put the image optimization end into security testing. |
For more reference, I've been able to narrow down where the issue was introduced: In 13.5.7-canary.17, the middleware catches |
Just FYI: I actually stumbled on this issue a while ago, when I was working on 2 ideas:
|
Actually, I tried to access this feature in middleware for the same reason. For now, we continue by allowing only certain hosts and certain sizes as you said. If we can trigger it in image requests, we will continue by adding a customized headers. But thanks for the heads up anyway :) |
Any updates on this? Next/image is virtually unusable in its current state. Maybe have a maintainer look at this? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I have a similar but different use case to Koen's: I am using a "public" image URL coming from the browser, but need to rewrite it to an "internal" URL of a server inside my k8s cluster. This should be doable by the middleware when this issue is fixed. |
Nice, that's actually a use case that my team kept pushing back because of this issue. |
Link to the code that reproduces this issue
https://github.com/HidayetCanOzcan/middleware-bug
To Reproduce
Current vs. Expected behavior
After running the application I expected to see a log message that shows image requests but only pathnames listed is;
/_next/image is missing
Provide environment information
Which area(s) are affected? (Select all that apply)
Image (next/image), Middleware
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local)
Additional context
I also tried to add matcher for the image path and also try to add it to config file as image path but none of them resolve the issue.
The text was updated successfully, but these errors were encountered: