Repository navigation
fix(images): the untrusted image fetch closes six gaps a security review found - #278
Conversation
…iew found - IPv6 outside 2000::/3 is not public. Only that block is allocated for global unicast; the rest is special-purpose or unallocated space, which a network can route to itself. The deprecated IPv4-compatible form (::a.b.c.d) is refused whatever it carries. - A network's own NAT64 prefix (RFC 6052) is honoured: an IPv6 address under it stands for an IPv4 address, which must be public too. The prefixes are read from the resolver's answer for ipv4only.arpa (RFC 7050), kept five minutes, and asked for only when a fetch goes to an IPv6 address. - The resolver is asked for every address of a name without ADDRCONFIG, the hint Node adds that leaves out a family the machine has no address of. On an IPv6-only network it hid a name's private IPv4 address behind the NAT64 address made from it. - A compressed body is counted on the wire as well as decoded: a gzip header's file name is megabytes that decode to nothing. - The deadline ends the decoder too, which can hold input after the response has ended, and an image given in the string itself (a data URL, raw base64) is held to maxBytes. - The address a name resolved to, and the resolver's error, are no longer properties of the refusal: imageUrlRefusalDetail(error) gives them for a log. util.inspect prints an error's cause, which told a missing name from a refused one.
|
Warning Review limit reached
This review includes 7 billable files and costs up to $1.75.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 2 minutes for your next included review. View limit details
Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Reviewer's GuideCloses six untrusted-image-fetch security gaps by validating all relevant IPv4/IPv6 and DNS64/NAT64 paths, enforcing byte limits before and after content decoding—including inline inputs—and making timeouts terminate decoder work, while separating sensitive refusal diagnostics from exposed errors. Sequence diagram for the hardened untrusted image fetchsequenceDiagram
participant Caller
participant Fetch as fetchUntrustedImage
participant DNS as dns.lookup
participant Server as HTTP_Server
participant Decoder as Content_Decoder
Caller->>Fetch: fetchUntrustedImage(source, options)
Fetch->>Fetch: isPublicNetworkAddress(source)
Fetch->>DNS: lookup(hostname, all, without ADDRCONFIG)
DNS-->>Fetch: IPv4 and IPv6 addresses
opt IPv6 address resolved
Fetch->>DNS: lookup(ipv4only.arpa, family 6, all)
DNS-->>Fetch: NAT64 prefix addresses
Fetch->>Fetch: nat64PrefixesFrom(addresses)
Fetch->>Fetch: isPublicNetworkAddress(address, nat64Prefixes)
end
Fetch->>Server: GET with checked connection
Server-->>Fetch: response and redirects
opt redirect
Fetch->>Fetch: check redirect address
Fetch->>Server: GET redirected URL
end
Server-->>Decoder: compressed response body
Decoder->>Decoder: enforce encoded and decoded maxBytes
Fetch->>Decoder: readBody(response, signal)
alt timeout or size limit
Fetch->>Decoder: destroy(error)
Fetch->>Server: destroy(error)
else valid body
Decoder-->>Caller: image Buffer
end
Flow diagram for bounded trusted and untrusted image inputsflowchart TD
A["imageToBuffer(input, options)"] --> B{untrusted?}
B -- no --> C[Decode or fetch input]
B -- yes --> D["untrustedByteLimit(maxBytes)"]
D --> E{Input kind}
E -- data URL --> F[Decode payload]
E -- raw base64 --> G[Decode base64]
E -- http or https URL --> H[fetchUntrustedImage]
F --> I[sizeCheck]
G --> I
I --> J{Within maxBytes?}
J -- no --> K[Refuse oversized image]
J -- yes --> L[Return image Buffer]
H --> M[Check URL, DNS results, and redirects]
M --> N[Read wire bytes and decoded bytes]
N --> O{Within maxBytes and timeout?}
O -- no --> K
O -- yes --> L
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
PR Summary by QodoHarden untrusted image fetching against network and size-limit bypasses
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Code Review by Qodo
1.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0f2a34c5ef
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- A resolver that fails to say whether the network has a NAT64 prefix (any error but "no such address") no longer counts as "no prefix": the IPv6 address is refused, and the question is asked again next time. - The prefix cache entry is stored before the resolver is asked. A resolver that answered at once with an error removed nothing and then had its failure kept for five minutes. - A cached prefix is used only on the network it was learned on: the entry carries the machine's interface addresses. - nat64PrefixesFrom requires byte 8 to be zero where RFC 6052 reserves it, so bytes that only happen to spell 192.0.0.170 name no prefix. - An inline image's size is worked out from its text before decoding, so one over the limit is not allocated. - A test holds zlib's gunzip open past the end of the response and shows the fetch gives up at its deadline, not when the decoder is done.
## [0.13.40](v0.13.39...v0.13.40) (2026-10-11) ### feat * **auth:** OAuth for a web server: a redirect flow, sealed secrets and a sealed token store (#242) ([59a20d1](59a20d1)) * **voice-pipeline:** build a speech-to-text chain from provider entries (#176) ([29046f2](29046f2)) ### fix * **images:** a local A1111 edit reports the checkpoint the server rendered with (#279) ([3744044](3744044)) * **images:** the untrusted image fetch closes six gaps a security review found (#278) ([b99ecbc](b99ecbc)) * **memory:** the guarded fetch's deadline covers decoding, and a network refusal names no resolver detail (#280) ([7d8bc9e](7d8bc9e)) ### docs * eleventh round of audit follow-ups (two pages published, the agent() and gmi() guides aligned) (#264) ([d4d3c6d](d4d3c6d))
What this fixes
imageToBuffer(source, { untrusted: true })is the fetch for a URL a model's tool call or a user gave. Its promise: public network addresses only, checked at every connection and every redirect, within 50 MiB and 30 seconds. A security review found six ways around it.http://[4000::1]/secret, on a network that routes that space to itself2000::/3is public: it is the one block allocated for global unicast (IANA). The deprecated IPv4-compatible form (::a.b.c.d) is refused whatever it carrieshttp://[<prefix>::a9fe:a9fe]/, which a NAT64 gateway sends to 169.254.169.254ipv4only.arpa(RFC 7050), read by the layouts of RFC 6052, kept five minutes on the network they were learned on, and asked for only when a fetch goes to an IPv6 address. When the resolver fails to answer that question, the IPv6 address is refusedinternal.examplewith the address 10.1.2.3 resolved to the NAT64 address a DNS64 resolver made from it, and nothing elseADDRCONFIG, the hint Node adds to a connection's lookup, so both families are checkeddata:image/png;base64,followed by 70 MiBmaxBytes. Its size is worked out from the text, so one over the limit is not decodedOne more change keeps a refusal from telling which internal names exist. The message was already the same for a name that resolves to a refused address and one that does not resolve, but the address and the resolver's error were properties of the error, and
util.inspectprints an error'scause. They move off the error:imageUrlRefusalDetail(error)returns them for a log.A network that announces its NAT64 prefix by other means than DNS64 (a router advertisement, PCP) is not covered;
fetchUntrustedImage'sallowAddressis the place for a host's own rule.Behaviour that changes
isPublicNetworkAddressreturnsfalsefor IPv6 outside2000::/3and for::a.b.c.d. It takes an optional second argument,{ nat64Prefixes }.error.resolvedAddressanderror.causeare gone from a refusal (they were added in 0.13.30); useimageUrlRefusalDetail(error).memory'sguardedFetchusesisPublicNetworkAddress, so it gets the first row of the table. The lookup and size changes are in the image fetch alone.Tests
networkAddress.test.ts: the reserved blocks; an address under a /32, /64 and /96 prefix that carries a private, link-local or loopback IPv4 address;nat64PrefixesFromagainst the six layouts of RFC 6052's own example table.untrustedImageFetch.test.ts, against a local server:alland withoutADDRCONFIG;https:URL: a refused name opens no connection, an allowed one opens its own;maxBytesare refused when untrusted, and read when trusted.untrustedImageFetch.deadline.test.tspins the decoder and the deadline. The real decoder finishes within milliseconds of the response, so the test replaces zlib's gunzip with one that holds its output for 600 ms: the fetch must give up at its 150 ms deadline. Before this change it returned the image at 600 ms.The review of the first commit added: a resolver that fails the NAT64 question refuses the address and is asked again next time; the prefix cache entry is stored before the resolver is asked (a resolver that answered at once with an error had its failure kept);
nat64PrefixesFromrequires byte 8 to be zero where RFC 6052 reserves it.