fix(mcp): split header value only on first colon in headerParser#39401
Open
furkankoykiran wants to merge 2 commits intomicrosoft:mainfrom
Open
fix(mcp): split header value only on first colon in headerParser#39401furkankoykiran wants to merge 2 commits intomicrosoft:mainfrom
furkankoykiran wants to merge 2 commits intomicrosoft:mainfrom
Conversation
The headerParser function used arg.split(':') which splits on ALL
colons in the string. JavaScript destructuring only captures the first
two array elements, silently discarding content after the second colon.
This caused header values containing colons (URLs with ://, port
numbers, Base64 strings) to be silently truncated.
The fix uses indexOf(':') + substring() to split only on the first
colon, matching the HTTP header spec (RFC 7230 Section 3.2).
Fixes microsoft/playwright-mcp#1417
Add comprehensive tests for the headerParser function to verify that header values containing colons (URLs, multi-colon values) are preserved correctly. Fixes microsoft/playwright-mcp#1417
Author
|
@microsoft-github-policy-service agree |
yury-s
reviewed
Feb 25, 2026
| const result: Record<string, string> = previous || {}; | ||
| const [name, value] = arg.split(':').map(v => v.trim()); | ||
| const colonIndex = arg.indexOf(':'); | ||
| if (colonIndex === -1) |
Member
There was a problem hiding this comment.
This will lose support for headers with empty value.
| */ | ||
|
|
||
| import { test, expect } from '@playwright/test'; | ||
| import { headerParser } from '../../packages/playwright/src/mcp/browser/config'; |
Member
There was a problem hiding this comment.
Let's instead add an integration test that validates the user-facing functionality. We normally don't write unit tests in playwright.
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.
Summary
Fix
headerParserfunction inpackages/playwright/src/mcp/browser/config.tsthat silently truncates header values containing colons.Problem
The
headerParserfunction usedarg.split(':')which splits on all colons in the string. JavaScript destructuringconst [name, value]only captures the first two array elements, silently discarding any content after the second colon.This caused header values containing colons to be silently truncated:
X-Custom: http://example.comhttp://example.comhttp❌X-Forwarded-Proto: value:with:colonsvalue:with:colonsvalue❌This affects:
--cdp-headerCLI flagPLAYWRIGHT_MCP_CDP_HEADERSenvironment variablehttp://,https://), port numbers (host:port), or Base64 strings with colonsSolution
Replace
arg.split(':')witharg.indexOf(':')+arg.substring()to split only on the first colon, matching the HTTP header spec (RFC 7230 Section 3.2).export function headerParser(arg: string | undefined, previous?: Record<string, string>): Record<string, string> { if (!arg) return previous || {}; const result: Record<string, string> = previous || {}; - const [name, value] = arg.split(':').map(v => v.trim()); - result[name] = value; + const colonIndex = arg.indexOf(':'); + if (colonIndex === -1) + return result; + const name = arg.substring(0, colonIndex).trim(); + const value = arg.substring(colonIndex + 1).trim(); + result[name] = value; return result; }Test Results
Added unit tests in
tests/mcp/header-parser.spec.tscovering:://)previousparameterLocal verification: 8/8 tests passed
Fixes microsoft/playwright-mcp#1417