AI Engineering Workspace
PartialChat, files, terminal and preview in one place. Chat sessions run on a durable Postgres-backed queue (chat only: no tools or shell). Live models need an API key; the terminal is unavailable.
Project files
read-onlyapp/src/lib/ssrf.ts
1import dns from "node:dns/promises";2import net from "node:net";34function isPrivateIp(ip: string): boolean {5 if (net.isIPv4(ip)) {6 const [a, b] = ip.split(".").map(Number);7 return a === 0 || a === 10 || a === 127 || (a === 169 && b === 254) || (a === 172 && b >= 16 && b <= 31) ||8 (a === 192 && b === 168) || (a === 100 && b >= 64 && b <= 127) || a >= 224;9 }10 const s = ip.toLowerCase();11 if (s.startsWith("::ffff:")) return isPrivateIp(s.slice(7));12 return s === "::1" || s === "::" || s.startsWith("fc") || s.startsWith("fd") || s.startsWith("fe80");13}1415/** Fetch an external URL defensively: http(s) only, public IPs only (checked per hop), manual redirects, size/time caps. */16export async function safeFetch(url: string, opts: { maxBytes: number; timeoutMs?: number; maxRedirects?: number }): Promise<{ bytes: Buffer; contentType: string; finalUrl: string }> {17 let cur = new URL(url);18 for (let hop = 0; hop <= (opts.maxRedirects ?? 3); hop++) {19 if (cur.protocol !== "https:" && cur.protocol !== "http:") throw new Error("only http(s) URLs are allowed");20 if (cur.username || cur.password) throw new Error("credentials in URL not allowed");21 const host = cur.hostname.replace(/^\[|\]$/g, "");22 const addrs = net.isIP(host) ? [{ address: host }] : await dns.lookup(host, { all: true });23 if (!addrs.length || addrs.some(a => isPrivateIp(a.address))) throw new Error("destination resolves to a non-public address");24 // NOTE: DNS-rebinding window between lookup and connect is a known residual risk (documented in SPEC threat T11).25 const ctl = new AbortController();26 const to = setTimeout(() => ctl.abort(), opts.timeoutMs ?? 10_000);27 try {28 const res = await fetch(cur, { redirect: "manual", signal: ctl.signal, headers: { "user-agent": "zoo-cloud-studio-ingest/0.1" } });29 if (res.status >= 300 && res.status < 400 && res.headers.get("location")) { cur = new URL(res.headers.get("location")!, cur); continue; }30 if (!res.ok) throw new Error(`upstream returned ${res.status}`);31 const len = Number(res.headers.get("content-length") || 0);32 if (len > opts.maxBytes) throw new Error("file too large");33 const chunks: Buffer[] = []; let size = 0;34 for await (const c of res.body as any) { size += c.length; if (size > opts.maxBytes) throw new Error("file too large"); chunks.push(Buffer.from(c)); }35 return { bytes: Buffer.concat(chunks), contentType: res.headers.get("content-type") || "", finalUrl: cur.toString() };36 } finally { clearTimeout(to); }37 }38 throw new Error("too many redirects");39}40
Conversation
PartialSign in to start AI sessions.
Task checklist
- Application shell deployed
- Persistent projects
- Agent runtime
- Sandboxed terminal
Execution activity
No agent sessions. Git HEAD 0eebc42 on master.
Approval requests
None pending.