Skip to content

Commit bb9d3c5

Browse files
committed
update header list and doc
1 parent b4c06ce commit bb9d3c5

File tree

2 files changed

+49
-22
lines changed

2 files changed

+49
-22
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,7 +2958,7 @@
29582958
},
29592959
"requestHeaders": {
29602960
"type": "object",
2961-
"description": "Additional HTTP headers to include with requests to this model. These reserved headers are not allowed and ignored if present: ['api-key', 'authorization', 'content-type', 'openai-intent', 'x-github-api-version', 'x-initiator', 'x-interaction-id', 'x-interaction-type', 'x-onbehalf-extension-id', 'x-request-id', 'x-vscode-user-agent-library-version']",
2961+
"description": "Additional HTTP headers to include with requests to this model. These reserved headers are not allowed and ignored if present: forbidden request headers (https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_request_header), forwarding headers ('forwarded', 'x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto'), and others ('api-key', 'authorization', 'content-type', 'openai-intent', 'x-github-api-version', 'x-initiator', 'x-interaction-id', 'x-interaction-type', 'x-onbehalf-extension-id', 'x-request-id', 'x-vscode-user-agent-library-version'). Pattern-based forbidden headers ('proxy-*', 'sec-*', 'x-http-method*' with forbidden methods) are also blocked.",
29622962
"additionalProperties": {
29632963
"type": "string"
29642964
}
@@ -3034,7 +3034,7 @@
30343034
},
30353035
"requestHeaders": {
30363036
"type": "object",
3037-
"description": "Additional HTTP headers to include with requests to this model. These reserved headers are not allowed and ignored if present: ['api-key', 'authorization', 'content-type', 'openai-intent', 'x-github-api-version', 'x-initiator', 'x-interaction-id', 'x-interaction-type', 'x-onbehalf-extension-id', 'x-request-id', 'x-vscode-user-agent-library-version']",
3037+
"description": "Additional HTTP headers to include with requests to this model. These reserved headers are not allowed and ignored if present: forbidden request headers (https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_request_header), forwarding headers ('forwarded', 'x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto'), and others ('api-key', 'authorization', 'content-type', 'openai-intent', 'x-github-api-version', 'x-initiator', 'x-interaction-id', 'x-interaction-type', 'x-onbehalf-extension-id', 'x-request-id', 'x-vscode-user-agent-library-version'). Pattern-based forbidden headers ('proxy-*', 'sec-*', 'x-http-method*' with forbidden methods) are also blocked.",
30383038
"additionalProperties": {
30393039
"type": "string"
30403040
}

src/extension/byok/node/openAIEndpoint.ts

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,39 @@ function hydrateBYOKErrorMessages(response: ChatResponse): ChatResponse {
4545

4646
export class OpenAIEndpoint extends ChatEndpoint {
4747
// Reserved headers that cannot be overridden for security and functionality reasons
48+
// Including forbidden request headers: https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_request_header
4849
private static readonly _reservedHeaders: ReadonlySet<string> = new Set([
49-
// Authentication & Authorization
50-
'api-key',
51-
'authorization',
52-
'cookie',
53-
'set-cookie',
54-
// Content & Protocol
55-
'content-type',
50+
// Forbidden Request Headers
51+
'accept-charset',
52+
'accept-encoding',
53+
'access-control-request-headers',
54+
'access-control-request-method',
55+
'connection',
5656
'content-length',
57-
'transfer-encoding',
57+
'cookie',
58+
'date',
59+
'dnt',
60+
'expect',
5861
'host',
59-
// Routing & Proxying
60-
'proxy-authorization',
61-
'proxy-authenticate',
62+
'keep-alive',
63+
'origin',
64+
'permissions-policy',
65+
'referer',
66+
'te',
67+
'trailer',
68+
'transfer-encoding',
69+
'upgrade',
70+
'user-agent',
71+
'via',
72+
// Forwarding & Routing
73+
'forwarded',
6274
'x-forwarded-for',
6375
'x-forwarded-host',
6476
'x-forwarded-proto',
65-
'forwarded',
66-
// Security & CORS
67-
'origin',
68-
'referer',
69-
'sec-fetch-site',
70-
'sec-fetch-mode',
71-
'sec-fetch-dest',
72-
// Application-specific
77+
// Others
78+
'api-key',
79+
'authorization',
80+
'content-type',
7381
'openai-intent',
7482
'x-github-api-version',
7583
'x-initiator',
@@ -78,7 +86,10 @@ export class OpenAIEndpoint extends ChatEndpoint {
7886
'x-onbehalf-extension-id',
7987
'x-request-id',
8088
'x-vscode-user-agent-library-version',
81-
'user-agent',
89+
// Pattern-based forbidden headers are checked separately:
90+
// - 'proxy-*' headers (handled in sanitization logic)
91+
// - 'sec-*' headers (handled in sanitization logic)
92+
// - 'x-http-method*' with forbidden methods CONNECT, TRACE, TRACK (handled in sanitization logic)
8293
]);
8394

8495
// RFC 7230 compliant header name pattern: token characters only
@@ -164,6 +175,22 @@ export class OpenAIEndpoint extends ChatEndpoint {
164175
continue;
165176
}
166177

178+
// Check for pattern-based forbidden headers
179+
if (lowerKey.startsWith('proxy-') || lowerKey.startsWith('sec-')) {
180+
this.logService.warn(`[OpenAIEndpoint] Model '${this.modelMetadata.id}' attempted to set forbidden header pattern '${key}', skipping.`);
181+
continue;
182+
}
183+
184+
// Check for X-HTTP-Method* headers with forbidden methods
185+
if ((lowerKey === 'x-http-method' || lowerKey === 'x-http-method-override' || lowerKey === 'x-method-override')) {
186+
const forbiddenMethods = ['connect', 'trace', 'track'];
187+
const methodValue = String(rawValue).toLowerCase().trim();
188+
if (forbiddenMethods.includes(methodValue)) {
189+
this.logService.warn(`[OpenAIEndpoint] Model '${this.modelMetadata.id}' attempted to set forbidden method '${methodValue}' in header '${key}', skipping.`);
190+
continue;
191+
}
192+
}
193+
167194
const sanitizedValue = this._sanitizeHeaderValue(rawValue);
168195
if (sanitizedValue === undefined) {
169196
this.logService.warn(`[OpenAIEndpoint] Model '${this.modelMetadata.id}' has invalid value for header '${key}': '${rawValue}', skipping.`);

0 commit comments

Comments
 (0)