Trust proxy-derived host information
Reverse-proxy deployment
Auth.js · Pipe
trustHost is an optional boolean that lets Auth.js rely on the request’s host header when the deployment safely controls it. Set it to true for trusted deployments, especially behind a trusted proxy.
trustHost tells Auth.js that the incoming request host is safe to use. Enable it only when the deployment platform safely sets the host header; Auth.js integrations may enable it automatically on recognized platforms.
trustHost?: boolean| Name | Type | Description |
|---|---|---|
trustHost | boolean | Whether Auth.js may trust the incoming request host header. |
import { Auth } from "@auth/core"
const request = new Request("https://example.com")
const response = await Auth(request, {
providers: [Google],
secret: "...",
trustHost: true,
})Pass trustHost: true when Auth.js should accept the request host header as trustworthy.
Reverse-proxy deployment
Recognized hosting platform
HTTPS production application
trustHost control?trustHost is a boolean Auth.js configuration property. It must be true when Auth.js relies on the incoming request's host header, provided the deployment platform sets that header safely.
Follow-up: What happens behind a proxy? Set trustHost: true, or use AUTH_TRUST_HOST=true, so Auth.js can trust proxy-provided host information when the proxy is trusted.
trustHost affect cookies?When true, cookies created by Auth.js are accessible only over HTTPS URLs. For HTTP URLs such as local development, the option defaults to false for convenience.
Follow-up: How can insecure local cookies be allowed explicitly? Set trustHost: false, although the documentation says this is not recommended.
Auth.js-based libraries may infer this setting automatically for hosting platforms known to set the host header safely, such as Vercel. Otherwise, configure it explicitly in the Auth.js options.
Follow-up: Which environment variable has the same purpose? AUTH_TRUST_HOST=true is the environment-variable equivalent of trustHost: true.
AUTH_TRUST_HOSThost headerX-Forwarded-HostUntrustedHostAuthConfig