Skip to content

Conversation

@saarya-cyera
Copy link

Summary

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.

Fixes microsoft/playwright-mcp#1337

Changes

  • packages/playwright/src/mcp/browser/context.ts: Update originOrHostGlob() to detect wildcard port patterns and generate the correct glob pattern
  • packages/playwright/src/mcp/config.d.ts: Document supported origin formats in JSDoc
  • tests/mcp/request-blocking.spec.ts: Add 4 tests for wildcard port functionality

Problem

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:

const wildcardPortMatch = originOrHost.match(/^(https?):\/\/([^/:]+):\*$/);
if (wildcardPortMatch) {
  const [, protocol, hostname] = wildcardPortMatch;
  return `${protocol}://${hostname}:*/**`;
}
Input Previous Output New Output
http://localhost:* *://http://localhost:*/** http://localhost:*/**
https://example.com:* *://https://example.com:*/** https://example.com:*/**
http://localhost:8000 http://localhost:8000/** (unchanged)
localhost *://localhost/** (unchanged)

Use Case

This is useful when you want to:

  • Allow only HTTP (not HTTPS) traffic to localhost
  • Allow localhost on any port while blocking other hosts
  • Have more granular control over protocol while keeping port flexibility

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.
@saarya-cyera saarya-cyera force-pushed the fix/mcp-origin-wildcard-port branch from 7608161 to 6f842bc Compare January 24, 2026 05:35
@saarya-cyera
Copy link
Author

@microsoft-github-policy-service agree company="Cyera"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MCP --allowed-origins with wildcard port (http://localhost:*) generates invalid glob pattern

1 participant