fix(translate): pin the LibreTranslate client connection to the vetted address#377
Merged
Merged
Conversation
…d address The client validated the target host and then issued a separate plain fetch, which re-resolves DNS at connect time. An attacker controlling the configured translate hostname's DNS could answer the pre-check with a public IP and rebind to an internal address (loopback, link-local/metadata) for the actual request, exfiltrating the api_key carried in the POST body. Route the request through withSafeFetch — the same IP-pinning path webhook and media delivery already use — so the connection is pinned to the pre-validated address(es) and redirects are refused. SSRF_ALLOWED_HOSTS and the WEBHOOK_SSRF_PROTECT opt-out are honored unchanged; abort/timeout behaviour is preserved via the request signal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The LibreTranslate client validated the target host and then issued a separate plain
fetch, which re-resolves DNS at connection time. An attacker able to influence the configured translate hostname's DNS could answer the pre-check with a public IP and rebind to an internal address (loopback, link-local/metadata) for the actual request — exfiltrating theapi_key, which travels in the POST body.Change
Route the request through the existing
withSafeFetch(url, init, use, { guard })primitive — the same IP-pinning path that webhook and server-side media delivery already use. The connection is pinned to the pre-validated address(es) via the undici dispatcher, so it cannot be re-resolved to an internal address between check and connect. Redirects are refused (the guard only validated the original host).Preserved behaviour
SSRF_ALLOWED_HOSTSallowlist and theWEBHOOK_SSRF_PROTECT=falseopt-out are honoured unchanged (wired via theguardflag).signal.Tests
libretranslate.client.spec.tsrewritten to assert the client routes through the pinned helper with the correct guard flag, that theapi_keyis sent in the body, and that the circuit-breaker accounting + SSRF exemption hold. Backendlint+build+ fulljestgreen.