feat(mcp): support wildcard port in allowedOrigins and blockedOrigins#38944
Merged
yury-s merged 2 commits intomicrosoft:mainfrom Feb 3, 2026
Merged
feat(mcp): support wildcard port in allowedOrigins and blockedOrigins#38944yury-s merged 2 commits intomicrosoft:mainfrom
yury-s merged 2 commits intomicrosoft:mainfrom
Conversation
Add support for wildcard port syntax like `http://localhost:*` in the network.allowedOrigins and network.blockedOrigins config options. This allows restricting browser requests to a specific protocol and hostname while accepting any port number. Previously, patterns like `http://localhost:*` would fail to parse as a valid URL, causing the code to fall through to legacy host-only mode and generate an invalid glob pattern like `*://http://localhost:*/**`. The fix detects wildcard port patterns and generates the correct glob pattern `http://localhost:*/**` which properly matches any port.
7608161 to
6f842bc
Compare
Contributor
Author
|
@microsoft-github-policy-service agree company="Cyera" |
yury-s
reviewed
Jan 26, 2026
yury-s
approved these changes
Jan 26, 2026
This comment has been minimized.
This comment has been minimized.
18bd274 to
83d9635
Compare
Contributor
Author
|
@yury-s thanks for the review! I fixed the comments and need another review to merge - would you have a minute to circle back to this? Thanks! |
Contributor
Test results for "MCP"4 failed 3650 passed, 129 skipped Merge workflow run. |
yury-s
approved these changes
Feb 3, 2026
Contributor
Author
|
Thanks @yury-s ! |
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
Add support for wildcard port syntax like
http://localhost:*in thenetwork.allowedOriginsandnetwork.blockedOriginsconfig options. This allows restricting browser requests to a specific protocol and hostname while accepting any port number.Fixes microsoft/playwright-mcp#1337
Changes
packages/playwright/src/mcp/browser/context.ts: UpdateoriginOrHostGlob()to detect wildcard port patterns and generate the correct glob patternpackages/playwright/src/mcp/config.d.ts: Document supported origin formats in JSDoctests/mcp/request-blocking.spec.ts: Add 4 tests for wildcard port functionalityProblem
Previously, patterns like
http://localhost:*would fail to parse as a valid URL, causing the code to fall through to legacy host-only mode and generate an invalid glob pattern like*://http://localhost:*/**which never matches anything.Solution
Detect wildcard port patterns with regex before attempting URL parsing:
http://localhost:**://http://localhost:*/**❌http://localhost:*/**✅https://example.com:**://https://example.com:*/**❌https://example.com:*/**✅http://localhost:8000http://localhost:8000/**localhost*://localhost/**Use Case
This is useful when you want to: