1
1
# HTTP Header Passthrough
2
2
3
+ ⚠️ ** Security Notice** : HTTP Header Passthrough is ** disabled by default** for security reasons. Only enable this feature if you understand the security implications and have reviewed which headers should be passed through to backing MCP servers.
4
+
3
5
The MCP Gateway supports ** HTTP Header Passthrough** , allowing specific headers from incoming client requests to be forwarded to backing MCP servers. This feature is essential for maintaining authentication context and request tracing across the gateway infrastructure.
4
6
5
7
## Overview
@@ -8,66 +10,118 @@ When clients make requests through the MCP Gateway, certain headers (like authen
8
10
9
11
## Key Features
10
12
13
+ - ** 🔒 Security by Default** : Feature disabled by default - must be explicitly enabled
14
+ - ** 🛡️ Header Validation** : Server-side and client-side header name and value validation
15
+ - ** 🧹 Sanitization** : Automatic removal of dangerous characters and length limits
11
16
- ** Global Configuration** : Set default passthrough headers for all gateways
12
17
- ** Per-Gateway Override** : Customize header passthrough on a per-gateway basis
13
18
- ** Conflict Prevention** : Automatically prevents overriding existing authentication headers
14
19
- ** Admin UI Integration** : Configure passthrough headers through the web interface
15
20
- ** API Management** : Programmatic control via REST endpoints
21
+ - ** Rate Limiting** : Built-in rate limiting for configuration endpoints
16
22
17
23
## Configuration
18
24
25
+ ### ⚠️ Enable the Feature (Required)
26
+
27
+ ** The header passthrough feature is disabled by default for security.** You must explicitly enable it:
28
+
29
+ ``` bash
30
+ # Enable the feature (disabled by default)
31
+ ENABLE_HEADER_PASSTHROUGH=true
32
+
33
+ # Or in .env file
34
+ ENABLE_HEADER_PASSTHROUGH=true
35
+ ```
36
+
37
+ ** Warning** : Only enable this feature if you:
38
+ - Understand the security implications
39
+ - Have reviewed which headers should be passed through
40
+ - Trust the backing MCP servers with the forwarded headers
41
+ - Have implemented proper network security
42
+
19
43
### Environment Variables
20
44
21
45
Set global default headers using the ` DEFAULT_PASSTHROUGH_HEADERS ` environment variable:
22
46
23
47
``` bash
24
- # JSON array format
25
- DEFAULT_PASSTHROUGH_HEADERS=[" Authorization" , " X-Tenant-Id" , " X-Trace-Id" ]
48
+ # JSON array format (recommended)
49
+ DEFAULT_PASSTHROUGH_HEADERS=[" X-Tenant-Id" , " X-Trace-Id" ]
50
+
51
+ # Comma-separated format (also supported)
52
+ DEFAULT_PASSTHROUGH_HEADERS=X-Tenant-Id,X-Trace-Id
26
53
27
54
# Or in .env file
28
- DEFAULT_PASSTHROUGH_HEADERS=[" Authorization " , " X-Tenant-Id" , " X-Trace-Id" ]
55
+ DEFAULT_PASSTHROUGH_HEADERS=[" X-Tenant-Id" , " X-Trace-Id" ]
29
56
```
30
57
58
+ ** Security Notes** :
59
+ - ` Authorization ` header is ** not included in defaults** for security
60
+ - Only add ` Authorization ` if you fully understand the token leakage risks
61
+ - Header names are validated against pattern: ` ^[A-Za-z0-9-]+$ `
62
+ - Header values are sanitized (newlines removed, length limited to 4KB)
63
+
31
64
### Admin UI Configuration
32
65
66
+ ** Prerequisites** :
67
+ 1 . Set ` ENABLE_HEADER_PASSTHROUGH=true ` in your environment
68
+ 2 . Restart the MCP Gateway service
69
+
33
70
#### Global Configuration
34
71
Access the admin interface to set global passthrough headers that apply to all gateways by default.
35
72
73
+ 🛡️ ** Client-side validation** automatically checks:
74
+ - Header names match pattern ` ^[A-Za-z0-9-]+$ `
75
+ - Header values don't contain newlines or excessive length
76
+ - Invalid headers are rejected with clear error messages
77
+
36
78
#### Per-Gateway Configuration
37
79
When creating or editing gateways:
38
80
39
81
1 . Navigate to the ** Gateways** section in the admin UI
40
82
2 . Click ** Add Gateway** or edit an existing gateway
41
83
3 . In the ** Passthrough Headers** field, enter a comma-separated list:
42
84
```
43
- Authorization, X-Tenant-Id, X-Trace-Id
85
+ X-Tenant-Id, X-Trace-Id, X-Request -Id
44
86
```
87
+ ** ⚠️ Avoid including ` Authorization ` unless absolutely necessary**
45
88
4 . Gateway-specific headers override global defaults
89
+ 5 . The UI validates headers in real-time and shows security warnings
46
90
47
91
### API Configuration
48
92
93
+ ** Rate Limited** : Configuration endpoints are rate-limited (20-30 requests/minute) for security.
94
+
49
95
#### Get Global Configuration
50
96
``` bash
51
97
GET /admin/config/passthrough-headers
98
+ Authorization: Bearer < your-jwt-token>
52
99
```
53
100
54
101
Response:
55
102
``` json
56
103
{
57
- "passthrough_headers" : [" Authorization " , " X-Tenant-Id" , " X-Trace-Id" ]
104
+ "passthrough_headers" : [" X-Tenant-Id" , " X-Trace-Id" ]
58
105
}
59
106
```
60
107
61
108
#### Update Global Configuration
62
109
``` bash
63
110
PUT /admin/config/passthrough-headers
64
111
Content-Type: application/json
112
+ Authorization: Bearer < your-jwt-token>
65
113
66
114
{
67
- " passthrough_headers" : [" Authorization " , " X-Custom-Header" ]
115
+ " passthrough_headers" : [" X-Tenant-Id " , " X-Custom-Header" ]
68
116
}
69
117
```
70
118
119
+ ** Security Validation** : The API automatically:
120
+ - Validates header names against ` ^[A-Za-z0-9-]+$ ` pattern
121
+ - Rejects invalid characters and formats
122
+ - Sanitizes header values when used
123
+ - Logs all configuration changes for audit
124
+
71
125
## How It Works
72
126
73
127
### Header Processing Flow
@@ -101,23 +155,46 @@ graph LR
101
155
102
156
## Security Considerations
103
157
158
+ ### 🛡️ Security-by-Default Features
159
+
160
+ ** Feature Flag Protection** :
161
+ - Header passthrough is ** disabled by default** (` ENABLE_HEADER_PASSTHROUGH=false ` )
162
+ - Must be explicitly enabled with full awareness of security implications
163
+ - Can be disabled instantly by setting the flag to ` false `
164
+
165
+ ** Header Sanitization** :
166
+ - ** Injection Prevention** : Removes newlines (` \r\n ` ) that could enable header injection attacks
167
+ - ** Length Limiting** : Restricts header values to 4KB maximum to prevent DoS
168
+ - ** Control Character Filtering** : Removes dangerous control characters (except tab)
169
+ - ** Validation** : Header names must match ` ^[A-Za-z0-9-]+$ ` pattern
170
+
171
+ ** Rate Limiting** :
172
+ - Configuration endpoints limited to 20-30 requests/minute
173
+ - Prevents automated attacks on configuration
174
+ - Configurable via existing rate limiting settings
175
+
104
176
### Conflict Prevention
105
177
106
178
The system automatically prevents header conflicts:
107
179
108
180
- ** Basic Auth** : Skips ` Authorization ` header if gateway uses basic authentication
109
181
- ** Bearer Auth** : Skips ` Authorization ` header if gateway uses bearer token authentication
182
+ - ** Existing Headers** : Won't override pre-existing headers in base request
110
183
- ** Warnings** : Logs warnings when headers are skipped due to conflicts
111
184
112
185
### Header Validation
113
186
114
- - Headers are validated before forwarding
115
- - Empty or invalid headers are filtered out
116
- - Only explicitly configured headers are passed through
187
+ - ** Server-side validation** : Headers validated against security patterns
188
+ - ** Client-side validation** : Admin UI provides real-time validation feedback
189
+ - ** Case-insensitive matching** : Handles header case variations safely
190
+ - ** Empty filtering** : Empty or invalid headers are filtered out
191
+ - ** Explicit configuration** : Only explicitly configured headers are passed through
117
192
118
193
## Use Cases
119
194
120
195
### Authentication Context
196
+ ⚠️ ** Security Warning** : Be extremely careful when forwarding authentication tokens.
197
+
121
198
Forward authentication tokens to maintain user context:
122
199
``` bash
123
200
# Client request includes
@@ -150,14 +227,14 @@ X-Organization: acme_corp
150
227
151
228
### Basic Setup
152
229
``` bash
153
- # .env file
154
- DEFAULT_PASSTHROUGH_HEADERS=[" Authorization " ]
230
+ # .env file (Authorization not recommended in defaults)
231
+ DEFAULT_PASSTHROUGH_HEADERS=[" X-Tenant-Id " ]
155
232
```
156
233
157
234
### Multi-Header Configuration
158
235
``` bash
159
- # .env file with multiple headers
160
- DEFAULT_PASSTHROUGH_HEADERS=[" Authorization " , " X-Tenant-Id" , " X-Trace-Id" , " X-Request-Id" ]
236
+ # .env file with multiple headers (safer defaults)
237
+ DEFAULT_PASSTHROUGH_HEADERS=[" X-Tenant-Id" , " X-Trace-Id" , " X-Request-Id" ]
161
238
```
162
239
163
240
### Gateway-Specific Override
@@ -175,9 +252,17 @@ DEFAULT_PASSTHROUGH_HEADERS=["Authorization", "X-Tenant-Id", "X-Trace-Id", "X-Re
175
252
### Common Issues
176
253
177
254
#### Headers Not Being Forwarded
178
- - Verify header names in configuration match exactly (case-sensitive)
255
+
256
+ ** Most Common Cause - Feature Disabled** :
257
+ - ✅ ** Check** : Is ` ENABLE_HEADER_PASSTHROUGH=true ` set in your environment?
258
+ - ✅ ** Check** : Did you restart the gateway after setting the flag?
259
+ - ✅ ** Check** : Are you seeing "Header passthrough is disabled" in debug logs?
260
+
261
+ ** Other Causes** :
262
+ - Verify header names in configuration match exactly (case-insensitive matching)
179
263
- Check for authentication conflicts in logs
180
264
- Ensure gateway configuration overrides aren't blocking headers
265
+ - Verify header names pass validation (only letters, numbers, hyphens allowed)
181
266
182
267
#### Authentication Conflicts
183
268
If you see warnings like:
@@ -194,6 +279,19 @@ Skipping passthrough header 'Authorization' - conflicts with existing basic auth
194
279
- Restart the gateway after environment variable changes
195
280
- Verify database migration has been applied
196
281
- Check admin API responses to confirm configuration is saved
282
+ - Verify rate limiting isn't blocking your configuration requests (20-30/min limit)
283
+
284
+ #### Header Validation Errors
285
+ If you see validation errors in the Admin UI or API:
286
+
287
+ ** Header Name Validation** :
288
+ - Only letters, numbers, and hyphens allowed: ` A-Za-z0-9- `
289
+ - Examples: ✅ ` X-Tenant-Id ` , ` Authorization ` ❌ ` X_Tenant_ID ` , ` My Header `
290
+
291
+ ** Header Value Issues** :
292
+ - No newlines (` \r ` or ` \n ` ) allowed in values
293
+ - Maximum length: 4KB per header value
294
+ - Control characters are automatically removed
197
295
198
296
### Debug Logging
199
297
@@ -203,9 +301,12 @@ LOG_LEVEL=DEBUG
203
301
```
204
302
205
303
Look for log entries containing:
206
- - ` Passthrough headers configured `
207
- - ` Skipping passthrough header `
208
- - ` Adding passthrough header `
304
+ - ` Header passthrough is disabled ` - Feature flag is off
305
+ - ` Passthrough headers configured ` - Headers are being processed
306
+ - ` Skipping passthrough header ` - Header blocked due to conflict
307
+ - ` Adding passthrough header ` - Header successfully forwarded
308
+ - ` Invalid header name ` - Header name validation failed
309
+ - ` Header value became empty after sanitization ` - Header value was sanitized away
209
310
210
311
## API Reference
211
312
0 commit comments