PG1204 opened a new pull request, #9134: URL: https://github.com/apache/texera/pull/9134
### What changes were proposed in this PR? `/api/huggingface/media-proxy` checked only the URL it was given, then let Unirest follow redirects on its own. So an allowlisted host could redirect the server anywhere, including internal addresses (#9103). This applies the fix #7013 made on the Python side: - **Redirects are followed by hand.** The proxy now has its own Unirest instance with `followRedirects(false)`. The global config used by the Hub endpoints is unchanged. Each redirect comes back to the resource, and the next hop is checked before it is requested, up to 5 hops. A relative `Location` is resolved against the current URL. A missing or unparsable `Location`, or a sixth redirect, returns 502. - **Every hop gets the same checks:** https only (the scheme is compared case-insensitively, so `HTTPS://` now works), an allowlisted host, and every address the host resolves to must be public. The address check rejects private, loopback, link-local (including 169.254.169.254), shared (100.64.0.0/10), unique-local, multicast, reserved and documentation ranges. IPv4-mapped, IPv4-compatible and NAT64 IPv6 addresses are judged by the IPv4 address inside them. - **`hf.co` is added to the allowlist.** Hub file URLs (`https://huggingface.co/<repo>/resolve/main/<file>`) redirect to `us.aws.cdn.hf.co`. Without `hf.co`, re-checking each hop would break the most common Hugging Face media URL. Behaviour changes worth knowing: - `http://` media URLs are now refused (400), and the result panel shows such a value as text instead of media. `http://huggingface.co` and `http://replicate.delivery` already redirect to https, so no Hugging Face URL is lost. - As in #7013, the address check runs before the request, and the HTTP client resolves the host again to connect. That narrows DNS rebinding but does not close it. - Not changed here: for a non-redirect error, the upstream status is still passed back to the caller. #9103 mentions this as related. ### Any related issues? Closes #9103. ### How was this PR tested? 30 new tests in `HuggingFaceModelResourceSpec`, 114 in total, all passing. No existing test was changed. - Red-green: the tests were written first, against a version that only added the test seams. 26 failed, each for the expected reason. For example, the media client followed a real 302 instead of returning it, and a redirect to an off-allowlist host came back as 302 instead of 403. With the fix, all pass. Reverting the fix makes exactly those 26 fail again. - The root cause is pinned with the real HTTP client against a loopback server: the media client must hand back a 302 rather than follow it. The other proxy tests use the suite's existing stub client plus a fake resolver, so nothing leaves the machine. - Mutation check: switching off each defence in turn (no auto-follow, per-hop check, `hf.co`, embedded-IPv4 handling, the empty-resolution guard, the hop limit, https-only) is caught by its own tests. - Live check against the real network: a Hub file URL follows its redirect to `us.aws.cdn.hf.co` and returns the PNG. The same URL over `http://` returns 400, an off-allowlist host 403, and an unresolvable allowlisted name 502. - `scalafmtCheck` and `scalafix --check` are clean for both main and test. ### Was this PR authored or co-authored using generative AI tooling? Yes, this PR was co-authored with Claude in compliance with ASF policy. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
