Repository navigation
Use configurable public host for self-hosted response URLs - #3699
Conversation
There was a problem hiding this comment.
1 issue found across 10 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
|
fixed in c9a0c62. normalizeHost now returns undefined when the value cannot be parsed into a host, and getRequestHostname falls through to X-Forwarded-Host then req host instead of leaking the raw value. Added a test covering an unparseable SELF_HOSTED_DOMAIN (8 passing now). |
|
Open since early June. The cubic review is addressed and it's mergeable, the only red check is the Vercel preview deploy that needs maintainer auth on fork PRs. @mogery mind giving it a look when you have time? |
|
Suer |
|
Not sure why this makes sense. X-Forwarded-Host is already obeyed automatically if the firecrawl/apps/api/src/index.ts Lines 75 to 77 in 8d679cb |
|
Agreed that trust proxy is the right signal to lean on. One wrinkle: this repo is on Express 4.22, where the trust-proxy-aware accessor is So leaning purely on the framework on 4.x means either losing the port or still ignoring |
Gah, good catch, that's annoying. I'll port to Express 5. |
Ok, we are now on 5! #3860 @saivedant169 Could you please re-test whether it works now on latest, and if not, make the necessary updates? |
req.get("host") returns the raw Host header and ignores X-Forwarded-Host, so
behind a reverse proxy the absolute URLs in API responses (crawl/batch job
URLs, pagination links) pointed at the internal bind address instead of the
public host. On Express 5 req.host honors X-Forwarded-Host when trust proxy is
configured and keeps the port, so swapping req.get("host") for req.host makes
the response URLs use the public host without any extra config.
c9a0c62 to
5d79fea
Compare
|
@mogery reworked on latest main. Dropped the SELF_HOSTED_DOMAIN env var and the helper, it just uses req.host now across the crawl/batch/monitor/parse URL builders. On 5.x req.host honors X-Forwarded-Host with trust proxy and keeps the port, so the public host comes through with no extra config. I also caught one more spot still on req.get("host") (parse-upload) and switched that too. Typechecks clean against @types/express 5. |
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
|
Thanks! |
Problem
Self-hosted instances behind a reverse proxy build absolute URLs from
req.get("host"), which returns the internal bind address. Crawl/batch job URLs and paginationnextlinks come back pointing athttp://localhost:3002and are unreachable by the client.Fixes #2964
Fix
getRequestHostname(req)inapps/api/src/lib/host-utils.ts.v1/crawl,v1/batch-scrape,v1/crawl-status,v2/crawl,v2/batch-scrape,v2/crawl-status, andv2/monitorchecks.SELF_HOSTED_DOMAINenv, then the firstX-Forwarded-Hostvalue, thenreq.get("host"). Cloud behavior is unchanged when neither is set.SELF_HOSTED_DOMAINis normalized to a barehost[:port]even if an operator includes a scheme or path, and an empty or whitespace value is ignored, so the helper never produces malformed URLs likehttp://https://example.com.req.protocol, so paginationnextlinks stay valid.Scope is limited to the URL-emitting controllers plus the helper and its test. A prior attempt (#3015) mixed this fix with unrelated PDF, fire-engine, and SDK changes and was abandoned; this PR keeps the change focused and addresses the empty-value and malformed-URL edge cases that review flagged there.
Test plan
New unit test
apps/api/src/lib/__tests__/host-utils.test.tscovering the resolution order and normalization:Also ran
tsc --noEmit: no new type errors in the changed files. DocumentedSELF_HOSTED_DOMAINinapps/api/.env.example.Summary by cubic
Fixes broken absolute URLs behind reverse proxies by using Express’s
req.host. Crawl/batch job URLs, parse-upload links, and pagination now point to the external domain (including port) instead of the internal bind address.req.get("host")withreq.hostin v1/v2 crawl, batch-scrape, crawl-status, monitor checks, and v2 parse-upload; works withtrust proxyand needs no extra config.X-Forwarded-Hostand preserves ports; paginationnextlinks remain valid.Written for commit 5d79fea. Summary will update on new commits.