change scheme check

This commit is contained in:
Hailey
2025-09-01 10:31:49 -07:00
parent cb1b72ec1e
commit 777e3a0413
+4 -3
View File
@@ -14,6 +14,7 @@ import {redirectLogger} from '../logger.js'
const SAFELINK_MIN_FETCH_INTERVAL = 1_000 const SAFELINK_MIN_FETCH_INTERVAL = 1_000
const SAFELINK_MAX_FETCH_INTERVAL = 10_000 const SAFELINK_MAX_FETCH_INTERVAL = 10_000
const SCHEME_REGEX = /^[a-zA-Z][a-zA-Z0-9+.-]*:/
export class SafelinkClient { export class SafelinkClient {
private domainCache: LRUCache<string, SafelinkRule | 'ok'> private domainCache: LRUCache<string, SafelinkRule | 'ok'>
@@ -263,12 +264,12 @@ export class SafelinkClient {
} }
private static normalizeUrl(input: string) { private static normalizeUrl(input: string) {
if (!input.startsWith('https://')) { if (!SCHEME_REGEX.test(input)) {
input = `https://${input}` input = `https://${input}`
} }
const u = new URL(input) const u = new URL(input)
u.hash = '' u.hash = ''
let normalized = u.href.replace(/^[^:]+:\/\//, '').toLowerCase() let normalized = u.href.replace(SCHEME_REGEX, '').toLowerCase()
if (normalized.endsWith('/')) { if (normalized.endsWith('/')) {
normalized = normalized.substring(0, normalized.length - 1) normalized = normalized.substring(0, normalized.length - 1)
} }
@@ -276,7 +277,7 @@ export class SafelinkClient {
} }
private static normalizeDomain(input: string) { private static normalizeDomain(input: string) {
if (!input.startsWith('https://')) { if (!SCHEME_REGEX.test(input)) {
input = `https://${input}` input = `https://${input}`
} }
const u = new URL(input) const u = new URL(input)