Skip to content

Commit 6d4fe05

Browse files
saphidclaude
andcommitted
fix(shared): preview_open reports about: and mailto: as unsupported instead of misreading them
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 60aec28 commit 6d4fe05

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎packages/shared/src/preview.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,18 @@ describe("normalizePreviewUrl", () => {
171171
);
172172
}
173173
});
174+
175+
it("reports explicit non-web schemes instead of reading them as a host", () => {
176+
for (const [rawUrl, protocol] of [
177+
["about:blank", "about:"],
178+
["mailto:[email protected]", "mailto:"],
179+
["javascript:alert(1)", "javascript:"],
180+
] as const) {
181+
expect(() => normalizePreviewUrl(rawUrl)).toThrow(
182+
expect.objectContaining({ reason: "unsupported-protocol", protocol }),
183+
);
184+
}
185+
expect(normalizePreviewUrl("localhost:3000")).toBe("http://localhost:3000/");
186+
expect(normalizePreviewUrl("devbox:8080")).toBe("https://devbox:8080/");
187+
});
174188
});

‎packages/shared/src/preview.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ export function normalizePreviewUrl(rawUrl: string): string {
185185
if (trimmed.length === 0) {
186186
throw new PreviewUrlNormalizationError({ inputLength: rawUrl.length, reason: "empty" });
187187
}
188+
const explicitProtocol = previewUrlProtocol(trimmed);
189+
if (explicitProtocol !== undefined && KNOWN_NON_WEB_SCHEMES.has(explicitProtocol)) {
190+
throw new PreviewUrlNormalizationError({
191+
inputLength: rawUrl.length,
192+
reason: "unsupported-protocol",
193+
protocol: explicitProtocol,
194+
});
195+
}
188196
const useHttp = LOOPBACK_PREFIX_PATTERN.test(trimmed);
189197
const candidate = URL_SCHEME_WITH_AUTHORITY_PATTERN.test(trimmed)
190198
? trimmed

0 commit comments

Comments
 (0)