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
6 changes: 6 additions & 0 deletions .changeset/image-endpoint-cleanup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'astro': patch
'@astrojs/internal-helpers': patch
---

Tightens `isRemotePath()` to reject control characters after a leading slash and fixes the dev image endpoint origin check
2 changes: 1 addition & 1 deletion packages/astro/src/assets/endpoint/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function loadLocalImage(src: string, url: URL) {
const sourceUrl = new URL(src, url.origin);
// This is only allowed if this is the same origin
if (sourceUrl.origin !== url.origin) {
returnValue = undefined;
return undefined;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was dead-code before, always would try to load the remote image.

}
return loadRemoteImage(sourceUrl);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/internal-helpers/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ export function isRemotePath(src: string) {
return false;
}

// Check for Unix absolute path (starts with / but not // or /\)
// Check for Unix absolute path (starts with / followed by a normal path character)
// This needs to be before the backslash check
if (decoded[0] === '/' && decoded[1] !== '/' && decoded[1] !== '\\') {
if (decoded[0] === '/' && /^\/[\w.@-]/.test(decoded)) {
return false;
}

Expand Down
11 changes: 11 additions & 0 deletions packages/internal-helpers/test/path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ describe('isRemotePath', () => {
'\\%0Aexample.com/test',
'\\%0Dexample.com/test',

// CRLF injection in path (control chars after leading slash cause URL parser
// to treat the remainder as a protocol-relative URL)
'/%0d%0a/example.com',
'/%0d%0a/example.com:8080/path',
'/%0a/example.com',
'/%0d/example.com',
'/\r\n/example.com',
'/\n/example.com',
'/\r/example.com',
'/\t/example.com',

// IP addresses
'http://192.168.1.1/test',
'//192.168.1.1/test',
Expand Down
Loading