Skip to content

Commit b5da234

Browse files
Add environment variable control for trust proxy setting (#5226)
* feat: allow trust proxy setting to be configured via environment variable * fix: restore HTTP_DENY_LIST in .env.example after merge conflict * feat: add conditional handling for trust proxy * feat: add trust proxy environment variable documentation * feat: add trust proxy environment variable sample value * fix: handle empty trust proxy string in docker environment --------- Co-authored-by: Henry Heng <henryheng@flowiseai.com>
1 parent e48f28d commit b5da234

File tree

9 files changed

+66
-45
lines changed

9 files changed

+66
-45
lines changed

CONTRIBUTING.md

Lines changed: 40 additions & 39 deletions
Large diffs are not rendered by default.

docker/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,4 @@ JWT_REFRESH_TOKEN_EXPIRY_IN_MINUTES=43200
174174
# HTTP_DENY_LIST=
175175
# CUSTOM_MCP_SECURITY_CHECK=true
176176
# CUSTOM_MCP_PROTOCOL=sse #(stdio | sse)
177+
# TRUST_PROXY=true #(true | false | 1 | loopback| linklocal | uniquelocal | IP addresses | loopback, IP addresses)

docker/docker-compose-queue-prebuilt.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@ services:
140140
- REDIS_KEEP_ALIVE=${REDIS_KEEP_ALIVE}
141141
- ENABLE_BULLMQ_DASHBOARD=${ENABLE_BULLMQ_DASHBOARD}
142142

143-
# SECURITY
143+
# SECURITY
144144
- CUSTOM_MCP_SECURITY_CHECK=${CUSTOM_MCP_SECURITY_CHECK}
145145
- CUSTOM_MCP_PROTOCOL=${CUSTOM_MCP_PROTOCOL}
146146
- HTTP_DENY_LIST=${HTTP_DENY_LIST}
147+
- TRUST_PROXY=${TRUST_PROXY}
147148
healthcheck:
148149
test: ['CMD', 'curl', '-f', 'http://localhost:${PORT:-3000}/api/v1/ping']
149150
interval: 10s
@@ -282,10 +283,11 @@ services:
282283
- REDIS_KEEP_ALIVE=${REDIS_KEEP_ALIVE}
283284
- ENABLE_BULLMQ_DASHBOARD=${ENABLE_BULLMQ_DASHBOARD}
284285

285-
# SECURITY
286+
# SECURITY
286287
- CUSTOM_MCP_SECURITY_CHECK=${CUSTOM_MCP_SECURITY_CHECK}
287288
- CUSTOM_MCP_PROTOCOL=${CUSTOM_MCP_PROTOCOL}
288289
- HTTP_DENY_LIST=${HTTP_DENY_LIST}
290+
- TRUST_PROXY=${TRUST_PROXY}
289291
healthcheck:
290292
test: ['CMD', 'curl', '-f', 'http://localhost:${WORKER_PORT:-5566}/healthz']
291293
interval: 10s

docker/docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ services:
125125
- REDIS_KEEP_ALIVE=${REDIS_KEEP_ALIVE}
126126
- ENABLE_BULLMQ_DASHBOARD=${ENABLE_BULLMQ_DASHBOARD}
127127

128-
# SECURITY
128+
# SECURITY
129129
- CUSTOM_MCP_SECURITY_CHECK=${CUSTOM_MCP_SECURITY_CHECK}
130130
- CUSTOM_MCP_PROTOCOL=${CUSTOM_MCP_PROTOCOL}
131131
- HTTP_DENY_LIST=${HTTP_DENY_LIST}
132+
- TRUST_PROXY=${TRUST_PROXY}
132133
ports:
133134
- '${PORT}:${PORT}'
134135
healthcheck:

docker/worker/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,4 @@ JWT_REFRESH_TOKEN_EXPIRY_IN_MINUTES=43200
174174
# HTTP_DENY_LIST=
175175
# CUSTOM_MCP_SECURITY_CHECK=true
176176
# CUSTOM_MCP_PROTOCOL=sse #(stdio | sse)
177+
# TRUST_PROXY=true #(true | false | 1 | loopback| linklocal | uniquelocal | IP addresses | loopback, IP addresses)

docker/worker/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ services:
129129
- CUSTOM_MCP_SECURITY_CHECK=${CUSTOM_MCP_SECURITY_CHECK}
130130
- CUSTOM_MCP_PROTOCOL=${CUSTOM_MCP_PROTOCOL}
131131
- HTTP_DENY_LIST=${HTTP_DENY_LIST}
132-
132+
- TRUST_PROXY=${TRUST_PROXY}
133133
ports:
134134
- '${WORKER_PORT}:${WORKER_PORT}'
135135
healthcheck:

packages/server/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ JWT_REFRESH_TOKEN_EXPIRY_IN_MINUTES=43200
174174
# HTTP_DENY_LIST=
175175
# CUSTOM_MCP_SECURITY_CHECK=true
176176
# CUSTOM_MCP_PROTOCOL=sse #(stdio | sse)
177+
# TRUST_PROXY=true #(true | false | 1 | loopback| linklocal | uniquelocal | IP addresses | loopback, IP addresses)
177178

178179

179180
############################################################################################################

packages/server/src/commands/base.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export abstract class BaseCommand extends Command {
7777
ENABLE_BULLMQ_DASHBOARD: Flags.string(),
7878
CUSTOM_MCP_SECURITY_CHECK: Flags.string(),
7979
CUSTOM_MCP_PROTOCOL: Flags.string(),
80-
HTTP_DENY_LIST: Flags.string()
80+
HTTP_DENY_LIST: Flags.string(),
81+
TRUST_PROXY: Flags.string()
8182
}
8283

8384
protected async stopProcess() {
@@ -210,5 +211,6 @@ export abstract class BaseCommand extends Command {
210211
if (flags.CUSTOM_MCP_SECURITY_CHECK) process.env.CUSTOM_MCP_SECURITY_CHECK = flags.CUSTOM_MCP_SECURITY_CHECK
211212
if (flags.CUSTOM_MCP_PROTOCOL) process.env.CUSTOM_MCP_PROTOCOL = flags.CUSTOM_MCP_PROTOCOL
212213
if (flags.HTTP_DENY_LIST) process.env.HTTP_DENY_LIST = flags.HTTP_DENY_LIST
214+
if (flags.TRUST_PROXY) process.env.TRUST_PROXY = flags.TRUST_PROXY
213215
}
214216
}

packages/server/src/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,19 @@ export class App {
163163
this.app.use(express.urlencoded({ limit: flowise_file_size_limit, extended: true }))
164164

165165
// Enhanced trust proxy settings for load balancer
166-
this.app.set('trust proxy', true) // Trust all proxies
166+
let trustProxy: string | boolean | number | undefined = process.env.TRUST_PROXY
167+
if (typeof trustProxy === 'undefined' || trustProxy.trim() === '' || trustProxy === 'true') {
168+
// Default to trust all proxies
169+
trustProxy = true
170+
} else if (trustProxy === 'false') {
171+
// Disable trust proxy
172+
trustProxy = false
173+
} else if (!isNaN(Number(trustProxy))) {
174+
// Number: Trust specific number of proxies
175+
trustProxy = Number(trustProxy)
176+
}
177+
178+
this.app.set('trust proxy', trustProxy)
167179

168180
// Allow access from specified domains
169181
this.app.use(cors(getCorsOptions()))

0 commit comments

Comments
 (0)