mirror of
https://github.com/hanzo-apps/dataroom.git
synced 2026-10-30 14:47:36 +00:00
@vercel/edge-config read NOTHING in production. EDGE_CONFIG is unset on this deployment, so every `get()` threw, and every call site caught it and fell back to an empty default. Several of them additionally checked `process.env. EDGE_CONFIG` and returned early, so the fallback was not even a fallback — it was the only path. What that meant, live: emails / keywords the blacklist matched nothing — abuse filtering was off trustedTeams no team was ever trusted betaFeatures no beta feature was ever on customEmail no team ever got its own sender address lib/config.ts reads these from Hanzo KV under a `config:` prefix, so a value changes with a KV write rather than a deploy — which is the reason the app reached for an edge config service to begin with. Reads never throw: a KV outage returns the caller's fallback, exactly as these call sites already assumed, so config can never take down a request path. customEmail is a Record, not a list, and now says so — it was being read through the list helper, which would have discarded it. @vercel/functions and @vercel/edge-config have no importers left and are dropped from package.json; the lockfile is regenerated and `npm ci --dry-run` is clean. @vercel/blob still has 10 importers and stays until storage moves to S3. Verified with npx tsc --noEmit: 100 errors before and after. Co-authored-by: Hanzo Dev <[email protected]>
67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import { getStringList } from "@/lib/config";
|
|
|
|
import { isTrustedTeam } from "@/lib/edge-config/trusted-teams";
|
|
import { log } from "@/lib/utils";
|
|
import { validateUrlSecurity } from "@/lib/zod/url-validation";
|
|
|
|
type ValidationResult =
|
|
| { valid: true; url: string }
|
|
| { valid: false; message: string };
|
|
|
|
export async function validateRedirectUrl(
|
|
redirectUrl: string,
|
|
teamId: string,
|
|
): Promise<ValidationResult> {
|
|
const trimmed = redirectUrl.trim();
|
|
|
|
if (!trimmed) {
|
|
return { valid: true, url: "" };
|
|
}
|
|
|
|
let parsed: URL;
|
|
try {
|
|
parsed = new URL(trimmed);
|
|
} catch {
|
|
return { valid: false, message: "Invalid redirect URL" };
|
|
}
|
|
|
|
if (parsed.protocol !== "https:") {
|
|
return { valid: false, message: "Redirect URL must use HTTPS" };
|
|
}
|
|
|
|
if (!validateUrlSecurity(trimmed)) {
|
|
return {
|
|
valid: false,
|
|
message: "Redirect URL targets a disallowed resource",
|
|
};
|
|
}
|
|
|
|
const trusted = await isTrustedTeam(teamId);
|
|
if (!trusted) {
|
|
try {
|
|
const keywords = await getStringList("keywords");
|
|
if (Array.isArray(keywords) && keywords.length > 0) {
|
|
const matchedKeyword = keywords.find(
|
|
(keyword) =>
|
|
typeof keyword === "string" &&
|
|
trimmed.toLowerCase().includes(keyword.toLowerCase()),
|
|
);
|
|
|
|
if (matchedKeyword) {
|
|
log({
|
|
message: `Redirect URL blocked: ${matchedKeyword} \n\n \`Metadata: {teamId: ${teamId}, url: ${trimmed}}\``,
|
|
type: "error",
|
|
mention: true,
|
|
});
|
|
return { valid: false, message: "This URL is not allowed" };
|
|
}
|
|
}
|
|
} catch {
|
|
// Edge config unavailable; allow the URL through
|
|
}
|
|
}
|
|
|
|
// Return the sanitized URL (trimmed, with resolved origin)
|
|
return { valid: true, url: parsed.toString() };
|
|
}
|