Repository navigation
Conversation
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.
Fixes #807
getServer()has calledapp.enable('trust proxy')since the first commit. In Express that istrust proxy: true: every entry ofX-Forwarded-Foris trusted, soreq.ipbecomes the left-most entry, which is whatever the client put in the header before the request reached Cloud Run.req.hostnameandreq.protocolfollowX-Forwarded-HostandX-Forwarded-Protothe same way. Function code that keys rate limits, allowlists, geo decisions or audit logs onreq.iptherefore keys them on a client-chosen value.Cloud Run places one proxy in front of the function and appends the address it accepted the connection from as the last
X-Forwarded-Forentry, so one trusted hop is the setting that yields that address (the same value GoogleCloudPlatform/nodejs-docs-samples#3583 settled on for the Cloud Run samples).This change:
--trust-proxyflag /TRUST_PROXYenvironment variable (FrameworkOptions.trustProxy) that accepts a hop count,true,false, or a comma-separated list of trusted addresses or subnets, and passes it to Express as thetrust proxysetting;1;Behavior change: deployments behind an additional proxy layer that relied on
trueto reach the left-most entry now see the last entry; they can setTRUST_PROXY=2(or a hop count matching their topology) orTRUST_PROXY=trueto keep the previous behavior.Tests:
test/options.tscovers the default, CLI-over-env precedence, an address list andfalse;test/integration/http.tsadds aproxy headersblock asserting that with the default only the platform-added entry is reported, and thattrustProxy: truereproduces the old behavior.npm run build,npx mocha build/test --recursive(111 passing) andgts checkare clean on Node 22.