-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: add prefix filtering and loop detection for local images #83
Conversation
3062da5
to
297a914
Compare
297a914
to
4e6937a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a couple of questions.
return { | ||
statusCode: 400, | ||
body: 'Invalid source image path', | ||
headers: plainText |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess for all the spots with plain text headers we always want these responses as text, i.e. no scenario where it would make sense as JSON?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, these are for humans
const isLocal = !id.startsWith('http://') && !id.startsWith('https://') | ||
if (isLocal) { | ||
const url = new URL(event.rawUrl) | ||
url.pathname = id | ||
if (localPrefix && !url.pathname.startsWith(localPrefix)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're giving the option to pass in a localPrefix
to IPX for scenarios like Next.js that have a dedicated folder for static images correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it should do the trick! 🚀
Adds support for a
localPrefix
option, ensuring that local images can only be served from a specific path. Additionally, adds a header to prevent infinite loops where the source image matches the ipx server. This is done by adding anx-ipx-subrequest
header to source image requests. If this header is detected then it means there's a request loop.