feat: add internalUrl option to avoid hairpin-NAT on self-fetches#32
Draft
juliusknorr wants to merge 1 commit into
Draft
feat: add internalUrl option to avoid hairpin-NAT on self-fetches#32juliusknorr wants to merge 1 commit into
juliusknorr wants to merge 1 commit into
Conversation
When services.CoAuthoring.server.internalUrl is set alongside storage.externalHost, any URL passed to downloadUrlPromise whose origin matches externalHost is rewritten to use internalUrl instead. This avoids hairpin-NAT / split-horizon DNS failures when DocService fetches its own signed cache URLs (e.g. /downloadfile proxy, converter source downloads). Signed-off-by: Julius Knorr <jus@bitgrid.net> Assisted-by: ClaudeCode:claude-sonnet-4-6
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.
Problem
When DocService and its nginx reverse proxy are co-located on the same host, internally-generated signed file URLs use the public hostname (e.g.
https://eo.nextcloud.com/cache/...). When DocService or FileConverter fetches one of these URLs itself (via the/downloadfileproxy endpoint or a converter source download), the request must traverse the router. Many routers do not apply inbound NAT rules to traffic originating from the inside, so the connection fails or the TLS handshake breaks -- the classic hairpin-NAT / split-horizon DNS problem.Solution
Adds
services.CoAuthoring.server.internalUrlconfig key (default:"").When both
services.CoAuthoring.server.internalUrlandstorage.externalHostare set, any URL passed todownloadUrlPromisewhose origin matchesstorage.externalHosthas its origin rewritten tointernalUrlbefore the HTTP request is made. All URLs sent to browsers or included in Nextcloud callbacks are unaffected -- only the internal fetch path is rewritten.Configuration
Add to your environment config (e.g.
production-linux.json):{ "storage": { "externalHost": "https://eo.nextcloud.com" }, "services": { "CoAuthoring": { "server": { "internalUrl": "http://localhost:8080" } } } }storage.externalHostis the public base URL already used to build signed storage URLs.internalUrlis the address DocService can reach itself on directly -- typicallyhttp://localhost:<port>where port matchesservices.CoAuthoring.server.port.With both set, a fetch of
https://eo.nextcloud.com/cache/files/data/abc/output.docx?md5=...becomeshttp://localhost:8080/cache/files/data/abc/output.docx?md5=..., staying entirely on-host with no TLS or NAT involved.The rewrite is per-tenant aware and does not affect the
rejectUnauthorizedsetting or any other request options.