🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore(ui_markdown): whitelist images with valid ipv6 or ipv4 hostname (#3318)
marliessophiecdc41cf573e3
diff --git a/web/src/server/api/routers/utilities.ts b/web/src/server/api/routers/utilities.tsindex 79c68c4a68..af5963c504 100644--- a/web/src/server/api/routers/utilities.ts+++ b/web/src/server/api/routers/utilities.ts@@ -10,32 +10,33 @@ const IP_4_PRIVATE_B_SUBNET = "172.16.0.0/12";const IP_4_PRIVATE_C_SUBNET = "192.168.0.0/16";/**- * Check if the hostname is a private IP address+ * Check if the ipAddress is a private IP address* This function is used to protect against Server Side Request Forgery (SSRF) attacks.* SSRF attacks can cause the server to make requests to internal resources that should not be accessible.- * By checking if a hostname resolves to a private IP address, we can prevent such attacks.+ * By checking if a ipAddress resolves to a private IP address, we can prevent such attacks.*- * @param hostname - The hostname to check- * @returns True if the hostname is a private IP address, false otherwise+ * @param ipAddress - The ipAddress to check+ * @returns True if the ipAddress is a private IP address, false otherwise*/-const isPrivateIp = (hostname: string): boolean => {+const isPrivateIp = (ipAddress: string): boolean => {try {- if (Address6.isValid(hostname)) {- const address = new Address6(hostname);- return address.isLinkLocal() || address.isLoopback();- } else if (Address4.isValid(hostname)) {- const address = new Address4(hostname);- return [+ if (Address6.isValid(ipAddress)) {+ const address = new Address6(ipAddress);+ const isValidAddress6 = address.isLinkLocal() || address.isLoopback();+ if (isValidAddress6) return true;+ }+ if (Address4.isValid(ipAddress)) {+ const address = new Address4(ipAddress);+ const isValidAddress4 = [IP_4_LOOPBACK_SUBNET,IP_4_LINK_LOCAL_SUBNET,IP_4_PRIVATE_A_SUBNET,IP_4_PRIVATE_B_SUBNET,IP_4_PRIVATE_C_SUBNET,].some((subnet) => address.isInSubnet(new Address4(subnet)));- } else {- console.error("Invalid IP address:", hostname);- return false;+ if (isValidAddress4) return true;}+ return false;} catch (error) {console.error("IP parsing error:", error);return false;