fix: add URL validation for logo fields (#26522)

* fix(auth): add URL validation for organization logo fields

- Add URL validation utility for server-side fetched URLs
- Validate logo URLs in tRPC organization schema
- Validate logo URLs in API v2 team DTOs
- Add graceful fallback in logo route for invalid URLs
- Only allow HTTPS and image data URLs
- Add unit tests for URL validation

* fix: add missing IP range and type validation

- Add RFC 6598 CGNAT range (100.64.0.0/10) to blocked IPs
- Add @IsString() decorator before custom URL validators
- Add boundary tests for new IP range

* fix: address review feedback

   - Export validateUrlForSSRFSync via @calcom/platform-libraries
   - Fix nullable/optional order in Zod schema

* fix: block localhost hostname and explicit null check

- Add localhost to BLOCKED_HOSTNAMES for sync validation
- Use explicit null check (url == null) instead of falsy check

* fix: allow empty string in URL validation

* refactor: extract shared validation logic

- Extract validateUrlCore() to eliminate duplication between sync/async versions
- Add JSDoc to all exported functions for better discoverability
- Remove redundant comments that repeated function names
- Simplify existing comments to be more concise

* fix: reject empty strings in URL validator

Previously if (!url) allowed empty strings to bypass validation.
Now explicitly checks for null/undefined only
This commit is contained in:
Pedro Castro authored and GitHub committed 2026-01-08 22:03:54 +00:00
1 parent a5387bbffe
commit d9aef5b6a6
10 files changed
+488 -20

No files matched your search

+21 -1
View File
@@ -18,6 +18,7 @@ import {
WEBAPP_URL,
} from "@calcom/lib/constants";
import logger from "@calcom/lib/logger";
import { isTrustedInternalUrl, logBlockedSSRFAttempt, validateUrlForSSRF } from "@calcom/lib/ssrfProtection";
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
@@ -190,7 +191,26 @@ async function getHandler(request: NextRequest) {
const filteredLogo = teamLogos[logoDefinition.source] ?? logoDefinition.fallback;
try {
const response = await fetch(filteredLogo);
let response: Response;
// Internal URLs (fallbacks from WEBAPP_URL) are trusted
if (isTrustedInternalUrl(filteredLogo, WEBAPP_URL)) {
response = await fetch(filteredLogo);
}
// External URLs (including data URLs) need SSRF validation
else {
const validation = await validateUrlForSSRF(filteredLogo);
if (!validation.isValid) {
logBlockedSSRFAttempt(filteredLogo, validation.error || "Unknown", { subdomain });
// Graceful degradation: use default logo instead of error
response = await fetch(logoDefinition.fallback);
} else {
response = await fetch(filteredLogo, {
signal: AbortSignal.timeout(10000), // 10s conservative timeout
});
}
}
const arrayBuffer = await response.arrayBuffer();
let buffer: Buffer = Buffer.from(arrayBuffer);
let contentType = response.headers.get("content-type") || "image/png";