Skip to content

Commit

Permalink
Add whitelisting for imgproxy source URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
esdete2 committed Sep 6, 2024
1 parent 9f6db4f commit 579395e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/imgproxy/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { urlSafeBase64 } from './utils';
import { ImageLoaderProps } from 'next/image';

const imgProxyLoader =
(pathSegment: string = '_image') =>
(pathSegment: string = '_image', whitelistedSourceUrls: string[]) =>
({ src, width, quality }: ImageLoaderProps) => {
// If the source is not an S3 URL, return the original source
if (!src.startsWith('s3://')) return src;
// if the source url is not whitelisted, return the original src
if (!whitelistedSourceUrls.some((url) => src.startsWith(url))) {
return src;
}

const encodedUrl = urlSafeBase64(src);
const params = new URLSearchParams();
Expand Down

0 comments on commit 579395e

Please sign in to comment.