mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-10 13:34:16 +00:00
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { readEnv } from "@/lib/runtime-env";
|
|
|
|
/** Accept public HTTP URLs only; never expose URL credentials or CSP syntax. */
|
|
function parsePublicUrl(value?: string | null): URL | undefined {
|
|
if (!value || /[\s;]/.test(value)) return;
|
|
try {
|
|
const url = new URL(value);
|
|
if (
|
|
(url.protocol === "https:" || url.protocol === "http:") &&
|
|
!url.username &&
|
|
!url.password
|
|
)
|
|
return url;
|
|
} catch {
|
|
return;
|
|
}
|
|
}
|
|
|
|
export function getRegistryPresentation(
|
|
registryUrl?: string | null,
|
|
mediaUrl?: string | null,
|
|
) {
|
|
const registry = parsePublicUrl(registryUrl);
|
|
const media = parsePublicUrl(mediaUrl);
|
|
return {
|
|
registryUrl: registry?.href,
|
|
imageOrigins: Array.from(
|
|
new Set(
|
|
[registry?.origin, media?.origin].filter((origin): origin is string =>
|
|
Boolean(origin),
|
|
),
|
|
),
|
|
),
|
|
};
|
|
}
|
|
|
|
/** Same Registry base URL the backend installs artifacts from. */
|
|
export function readRegistryPresentation() {
|
|
return getRegistryPresentation(
|
|
readEnv("PROWLER_REGISTRY_INDEX_URL"),
|
|
readEnv("UI_REGISTRY_MEDIA_URL"),
|
|
);
|
|
}
|