From 777e3a0413d40f8c20a47f0d6bc7e937bba3489d Mon Sep 17 00:00:00 2001 From: Hailey Date: Mon, 1 Sep 2025 10:31:49 -0700 Subject: [PATCH] change scheme check --- bskylink/src/cache/safelinkClient.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bskylink/src/cache/safelinkClient.ts b/bskylink/src/cache/safelinkClient.ts index 626c7c1dac..906bcb5d41 100644 --- a/bskylink/src/cache/safelinkClient.ts +++ b/bskylink/src/cache/safelinkClient.ts @@ -14,6 +14,7 @@ import {redirectLogger} from '../logger.js' const SAFELINK_MIN_FETCH_INTERVAL = 1_000 const SAFELINK_MAX_FETCH_INTERVAL = 10_000 +const SCHEME_REGEX = /^[a-zA-Z][a-zA-Z0-9+.-]*:/ export class SafelinkClient { private domainCache: LRUCache @@ -263,12 +264,12 @@ export class SafelinkClient { } private static normalizeUrl(input: string) { - if (!input.startsWith('https://')) { + if (!SCHEME_REGEX.test(input)) { input = `https://${input}` } const u = new URL(input) u.hash = '' - let normalized = u.href.replace(/^[^:]+:\/\//, '').toLowerCase() + let normalized = u.href.replace(SCHEME_REGEX, '').toLowerCase() if (normalized.endsWith('/')) { normalized = normalized.substring(0, normalized.length - 1) } @@ -276,7 +277,7 @@ export class SafelinkClient { } private static normalizeDomain(input: string) { - if (!input.startsWith('https://')) { + if (!SCHEME_REGEX.test(input)) { input = `https://${input}` } const u = new URL(input)