mirror of
https://github.com/Unleash/unleash.git
synced 2025-11-24 20:06:55 +01:00
As part of preparation for ESM and node/TSC updates, this PR will make Unleash build with strictNullChecks set to true, since that's what's in our tsconfig file. Hence, this PR also removes the `--strictNullChecks false` flag in our compile tasks in package.json. TL;DR - Clean up your code rather than turning off compiler security features :)
28 lines
641 B
TypeScript
28 lines
641 B
TypeScript
export const validateOrigin = (origin: string | undefined): boolean => {
|
|
if (origin === undefined) {
|
|
return false;
|
|
}
|
|
if (origin === '*') {
|
|
return true;
|
|
}
|
|
|
|
if (origin?.includes('*')) {
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
const parsed = new URL(origin);
|
|
return typeof parsed.origin === 'string' && parsed.origin === origin;
|
|
} catch {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
export const validateOrigins = (origins: string[]): string | undefined => {
|
|
for (const origin of origins) {
|
|
if (!validateOrigin(origin)) {
|
|
return `Invalid origin: ${origin}`;
|
|
}
|
|
}
|
|
};
|