Repository navigation
fix(images): the untrusted fetch settles on a protocol upgrade, and four review follow-ups - #227
Conversation
…our review follow-ups A cold security read of #211 found: - A 101 Switching Protocols reply left the fetch pending forever. Node closes such a connection without an error when nothing listens for 'upgrade', and a closed request ignores destroy(), so neither the error nor the deadline ended the wait. The request now settles on a response, an error, the deadline, an upgrade or a bare close. - The refusal named the private address a host resolved to. It reaches whoever sent the URL, so a model told to try internal names could map the network one refusal at a time. The message leaves it out; the address stays on the error as a non-enumerable resolvedAddress. - isPublicNetworkAddress passed several blocks the IANA special-purpose registries mark not globally reachable: 192.88.99.0/24, 100::/63, 2001::/23, 3fff::/20 and 5f00::/16. - A data URL with spaces around ;base64 was percent-decoded; WHATWG Fetch reads it as base64. New tests cover each, and the claims that had none: a name with one refused address among several, one lookup per connection, IPv6 literals in brackets, deflate and br bodies, a server that never answers, a redirect chain over the deadline, and URL schemes in upper case.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
This review includes 6 billable files and costs up to $1.50.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 37 seconds for your next included review. View limit detailsLimit details: You’ve used all 4 included reviews currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (6)
Comment |
Reviewer's GuideThe PR hardens untrusted image fetching by making every HTTP request termination path settle, preventing DNS-address disclosure and validation/connectivity races, expanding special-purpose address blocking, and fixing WHATWG-compatible data URL base64 parsing, with focused network and parser regression tests. Sequence diagram for hardened untrusted image fetchingsequenceDiagram
participant Caller
participant Fetch as untrustedImageFetch
participant DNS as DNS resolver
participant Server as Image server
Caller->>Fetch: imageToBuffer(url)
Fetch->>DNS: checkedLookup(hostname)
DNS-->>Fetch: addresses
alt refused address
Fetch-->>Caller: refusal(hostname)
else allowed address
Fetch->>Server: http.get(url)
alt response
Server-->>Fetch: response
Fetch-->>Caller: image buffer
else protocol upgrade
Server-->>Fetch: 101 upgrade
Fetch->>Server: socket.destroy()
Fetch-->>Caller: refusal(error)
else error, close, or deadline
Server-->>Fetch: request termination
Fetch-->>Caller: rejection(error)
end
end
Flow diagram for public-address validationflowchart TD
A[Resolve hostname] --> B{Any address is non-public?}
B -->|Yes| C[Reject without sending request]
C --> D[Expose resolvedAddress only for logs]
B -->|No| E[Connect with one lookup per connection]
E --> F[Fetch image]
Flow diagram for data URL parsingflowchart TD
A[Parse data URL] --> B{Media type ends with ; spaces base64 spaces?}
B -->|Yes| C[Buffer.from payload as base64]
B -->|No| D[percentDecodeBytes payload]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
PR Summary by QodoFix untrusted image fetch hangs and tighten address refusals
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Code Review by Qodo
1. Refused addresses disappear from logs
|
## [0.13.23](v0.13.22...v0.13.23) (2026-10-10) ### fix * **gmi:** follow-ups from the reviews of #193 and #199 (#217) ([2bacb69](2bacb69)) * **gmi:** manager shutdown waits for creations in flight, bounds each GMI and runs once (#222) ([d99b126](d99b126)) * **images:** the untrusted fetch settles on a protocol upgrade, and four review follow-ups (#227) ([9efb4b5](9efb4b5)) * **vision:** the TrOCR and Florence-2 tiers get a Buffer image as a Blob (#229) ([7fe444a](7fe444a))
What this fixes
A cold security read of #211 (the untrusted mode of
imageToBuffer) found five defects on master.1. A
101 Switching Protocolsreply left the fetch pending forever (P2). Node's HTTP client, on a 101 withUpgradeandConnection: upgradeand no'upgrade'listener, closes the socket without an error (lib/_http_client.js,socketOnData). Neither'response'nor'error'fires.socketCloseListenermarks the request destroyed, so the deadline'srequest.destroy()returns at once and the promise never settles. Any public host could hold a tool call open forever;ToolExecutorawaitsexecute()with no deadline of its own.get()now settles on every way a request ends: a response, an error, the deadline (rejecting directly), an upgrade (with an'upgrade'listener that destroys the socket), or a bare'close'.2. The refusal named the private address a host resolved to (P3).
imageToBuffer: db.corp.internal resolves to 10.20.0.7, ...went back to whoever sent the URL. The packs return a refusal to the model as the tool's error, so a model steered to try internal names could map the network one refusal at a time (CWE-209). The message is nowimageToBuffer: <host> does not resolve to a public network address.The address stays on the error as a non-enumerableresolvedAddress, for logs. A refused IP literal still names itself, since the caller wrote it.3. Blocks the IANA registries mark not globally reachable passed as public (P3).
192.88.99.0/24100:0:0:1::/64100::/63now covers it and the discard prefix2001::/233fff::/205f00::/16Sources: the IPv4 and IPv6 special-purpose registries. A few globally reachable anycast blocks inside
2001::/23are refused with the rest; no image is served from them.4. A data URL with spaces around
;base64was percent-decoded (P3).data:image/png; base64,...decoded as base64 before #211. WHATWG Fetch reads it as base64: the media type ends with;, any spaces, thenbase64(fetch spec, data: URL processor). The test is now/; *base64 *$/i.Tests
untrustedImageFetch.test.ts, against the real local server:[::1]and[::ffff:127.0.0.1]URLs are refused before connecting;HTTP://andFILE:are read in any case;resolvedAddresshas it.networkAddress.test.tslists the new blocks.imageToBuffer.test.tscovers both base64 spacings.Not in this change
Summary by Sourcery
Harden untrusted image loading against hanging requests, private-network disclosure, unsafe address ranges, and non-standard data URL formatting.
Bug Fixes:
;base64marker correctly.Enhancements:
Tests: