Skip to content

Commit 8a7af20

Browse files
committed
feat: handle mailto from originWhitelist
1 parent 717953f commit 8a7af20

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/WebViewShared.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const defaultDeeplinkWhitelist = ['https:'] as const;
2020
const defaultDeeplinkBlocklist = [`http:`, `file:`, `javascript:`] as const;
2121

2222
const stringWhitelistToRegex = (originWhitelist: string): RegExp =>
23-
new RegExp(`^${escapeStringRegexp(originWhitelist).replace(/\\\*/g, '.*')}$`);
23+
new RegExp(escapeStringRegexp(originWhitelist).replace(/^(https?:\/\/|mailto:).*/, '^$1.*$'));
2424

2525
const matchWithRegexList = (
2626
compiledRegexList: readonly RegExp[],
@@ -42,8 +42,13 @@ const _passesWhitelist = (
4242
url: string,
4343
) => {
4444
try {
45-
const { origin } = new URL(url)
46-
return origin && matchWithRegexList(compiledWhitelist, origin)
45+
const { href, origin } = new URL(url)
46+
47+
if (origin && origin !== 'null') {
48+
return matchWithRegexList(compiledWhitelist, origin);
49+
}
50+
51+
return matchWithRegexList(compiledWhitelist, href)
4752
} catch {
4853
return false
4954
}

0 commit comments

Comments
 (0)