Skip to content

Commit 1db1259

Browse files
committed
Allow wildcards in TLS passthrough UI
1 parent c2116a2 commit 1db1259

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/components/settings/proxy-settings-card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { isWindows } from '../../util/ui';
88
import { WarningIcon, Icon } from '../../icons';
99

1010
import { isValidPortConfiguration, ProxyStore } from '../../model/proxy-store';
11-
import { isValidHostname } from '../../model/network';
11+
import { isValidHostnamePattern } from '../../model/network';
1212
import {
1313
serverVersion,
1414
desktopVersion,
@@ -112,7 +112,7 @@ const InputClearButton = styled(IconButton)`
112112
right: 2px;
113113
`;
114114

115-
const hostnameValidation = inputValidation(isValidHostname, "Should be a valid hostname");
115+
const hostnameValidation = inputValidation(isValidHostnamePattern, "Should be a valid hostname (with optional * wildcards)");
116116

117117
const isAbsoluteWindowsPath = (path: string) => /^([a-zA-Z]:[\\\/]|[\\\/])((?:[^<>:"\/\\|?*]+)[\\\/]?)*$/.test(path);
118118
const isAbsolutePosixPath = (path: string) => /^\/(?:[^/]+\/?)*$/.test(path);

src/model/network.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ export function isValidHost(host: string | undefined): boolean {
99
return !!host?.match(/^[A-Za-z0-9\-.]+(:\d+)?$/);
1010
}
1111

12+
export function isValidHostnamePattern(pattern: string | undefined): boolean {
13+
if (!pattern) return false;
14+
15+
if (isValidHostname(pattern)) return true;
16+
17+
// Not a valid hostname. Is it a URLPatternb wildcard pattern then?
18+
// Replace * with a letter to test if it's valid & usable:
19+
20+
const testHostname = pattern.replace(/\*/g, 'Z');
21+
return isValidHostname(testHostname) &&
22+
(!('URLPattern' in window) || // On old Electron, just allow anything
23+
// Use any here because TS doesn't have types yet:
24+
new (window.URLPattern as any)(`https://${pattern}`).test(`https://${testHostname}`));
25+
}
26+
1227
export function isValidHostname(hostname: string | undefined): boolean {
1328
return !!hostname?.match(/^[A-Za-z0-9\-.]+$/);
1429
}

0 commit comments

Comments
 (0)