8000
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/moody-geckos-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/netlify': patch
---

Fixes generated Netlify Image CDN allowlists to reject remote URLs that contain an allowed image origin only within their path or query string
4 changes: 2 additions & 2 deletions packages/integrations/netlify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function remotePatternToRegex(
): string | undefined {
let { protocol, hostname, port, pathname } = pattern;

let regexStr = '';
let regexStr = '^';

if (protocol) {
regexStr += `${protocol}://`;
Expand Down Expand Up @@ -125,7 +125,7 @@ function remoteImagesFromAstroConfig(
const remoteImages: string[] = [];
// Domains get a simple regex match
remoteImages.push(
...config.image.domains.map((domain) => `https?:\/\/${escapeRegex(domain)}\/.*`),
...config.image.domains.map((domain) => `^https?:\/\/${escapeRegex(domain)}\/.*$`),
);
// Remote patterns need to be converted to regexes
remoteImages.push(
Expand Down
13 changes: 13 additions & 0 deletions packages/integrations/netlify/test/functions/image-cdn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ describe('Image CDN', { timeout: 120000 }, () => {
);
});

it('rejects allowed patterns embedded in another URL', async () => {
assert.equal(
regexes[0]!.test(
'http://169.254.169.254/latest/meta-data/?url=https://example.net/image.jpg',
),
false,
);
assert.equal(
regexes[2]!.test('http://127.0.0.1:6379/?url=https://www.example.org/images/a.jpg'),
false,
);
});

it('treats metacharacters in a literal pathname as literals', async () => {
const spyLogger = new SpyLogger();
const logger = spyLogger.forkIntegrationLogger('test-spy');
Expand Down
Loading
0