Skip to content
Closed
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 packages/shared/src/preview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ describe("resolveSearchUrlTemplate", () => {
});

describe("normalizePreviewUrl", () => {
it("rejects an explicit about: URL as an unsupported protocol", () => {
expect(() => normalizePreviewUrl("about:blank")).toThrow(
expect.objectContaining({ reason: "unsupported-protocol", protocol: "about:" }),
);
});

it("rejects unparseable input without retaining credentials or tokens", () => {
const rawUrl = "https://user:password@example.com:bad/path?access_token=secret#fragment";
try {
Expand Down
9 changes: 9 additions & 0 deletions packages/shared/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ export function normalizePreviewUrl(rawUrl: string): string {
if (trimmed.length === 0) {
throw new PreviewUrlNormalizationError({ inputLength: rawUrl.length, reason: "empty" });
}
// Prefixing https:// would turn about:blank into a host:port parse error.
const explicitProtocol = previewUrlProtocol(trimmed);
if (explicitProtocol !== undefined && KNOWN_NON_WEB_SCHEMES.has(explicitProtocol)) {
throw new PreviewUrlNormalizationError({
inputLength: rawUrl.length,
reason: "unsupported-protocol",
protocol: explicitProtocol,
});
}
const useHttp = LOOPBACK_PREFIX_PATTERN.test(trimmed);
const candidate = URL_SCHEME_WITH_AUTHORITY_PATTERN.test(trimmed)
? trimmed
Expand Down
Loading