fast-browser-with-jev
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
export type OriginPolicy = "*" | string[];
|
||||
|
||||
export function isHttpUrl(value: string): URL | undefined {
|
||||
try {
|
||||
const url = new URL(value);
|
||||
if ((url.protocol !== "http:" && url.protocol !== "https:") || url.username || url.password || url.hostname.includes("*")) return undefined;
|
||||
return url;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function approvedOrigin(value: string, policy: OriginPolicy): boolean {
|
||||
const url = isHttpUrl(value);
|
||||
if (!url) return false;
|
||||
return policy === "*" || policy.includes(url.origin);
|
||||
}
|
||||
Reference in New Issue
Block a user