Skip to content

Configure Express trust proxy for Cloud Run / reverse proxy deployments - #2

Merged
fsu9913-gif merged 2 commits into
mainfrom
copilot/fix-review-comment-3447081477
Jun 21, 2026
Merged

Configure Express trust proxy for Cloud Run / reverse proxy deployments#2
fsu9913-gif merged 2 commits into
mainfrom
copilot/fix-review-comment-3447081477

Conversation

Copilot AI commented Jun 21, 2026

Copy link
Copy Markdown

Without trust proxy set, Express ignores X-Forwarded-For and resolves req.ip to the proxy's address—breaking IP-based rate limiting and audit logging when running behind Cloud Run or any reverse proxy.

Change

  • server.ts: Add app.set("trust proxy", 1) immediately after app instantiation so Express correctly derives client IPs from the forwarded header chain.
const app = express();
const PORT = Number(process.env.PORT) || 3000;

app.set("trust proxy", 1); // trust single Cloud Run hop
app.use(express.json());
app.use(cookieParser());

Copilot AI changed the title [WIP] Fix code as per review comment 3447081477 Configure Express trust proxy for Cloud Run / reverse proxy deployments Jun 21, 2026
Copilot AI requested a review from fsu9913-gif June 21, 2026 17:42
@fsu9913-gif
fsu9913-gif marked this pull request as ready for review June 21, 2026 18:14
Copilot AI review requested due to automatic review settings June 21, 2026 18:14
@fsu9913-gif
fsu9913-gif merged commit 6571db4 into main Jun 21, 2026
2 checks passed
@fsu9913-gif
fsu9913-gif deleted the copilot/fix-review-comment-3447081477 branch June 21, 2026 18:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR configures the Express server to correctly resolve client IP addresses (via req.ip) when deployed behind Cloud Run or another reverse proxy, so IP-based logging/rate-limiting logic works as intended.

Changes:

  • Set Express trust proxy to 1 immediately after app creation to honor forwarded IP headers behind a single proxy hop.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server.ts
@fsu9913-gif
fsu9913-gif requested a review from Copilot June 21, 2026 18:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread server.ts
const app = express();
const PORT = Number(process.env.PORT) || 3000;

app.set("trust proxy", 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants