Skip to content

fix: validate session IDs - #265

Merged
ruifigueira merged 2 commits into
mainfrom
rfigueira/session-id-validation
Nov 25, 2026
Merged

ruifigueira merged 2 commits into
mainfrom
rfigueira/session-id-validation

Conversation

@ruifigueira

Copy link
Copy Markdown
Collaborator

connect() and endpointURLString() reject malformed session IDs.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 3adebf70.

This review, of fcf46c79

💬 Approved with comments — The fix works on the fetch path. One WARNING: with RPC bindings the session ID is checked only after it has been passed to connectSession().

Findings: 1 warning (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #265.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] With RPC bindings, `connect()` passes the session ID to `connectSession()` before checking it, in both packages.
- **File:** packages/playwright-cloudflare/src/index.ts:56

📋 Code Quality: ⚠️ 1 warning

With RPC bindings, the session ID goes to connectSession() before it is checked.

Recommendation: 📝 Minor Comments

  • [WARNING] With RPC bindings, connect() passes the session ID to connectSession() before checking it, in both packages. (packages/playwright-cloudflare/src/index.ts:56)
View full review

Session ID is checked after connectSession() on RPC bindings

  • In playwright, connect() (packages/playwright-cloudflare/src/index.ts:165-169) calls binding.connectSession!(options.sessionId) first. The check runs later, inside connectDevtools through sessionPath().
  • Puppeteer has the same order. PuppeteerWorkers.ts calls connectSession(sessionId) before WorkersWebSocketTransport.create, and the check lives in create.
  • So a malformed ID such as .. or a/b reaches the RPC binding unchecked. The error only comes afterwards.
  • The new tests use a plain {} binding, so they never take this path.
  • Fix: check the ID at the top of connect() in both packages, before connectSession(). In playwright, calling sessionPath(options.sessionId) there is enough. A test with an RPC-style binding would cover it.

Minor: the /^[\w-]+$/ pattern is duplicated across the two packages.


✅ All other checks passed

🔒 Security: ✅ LGTM

Both transports now reject session IDs that do not match /^[\w-]+$/ before building the devtools URL path. Puppeteer's browser branch skips the check, but that branch does not put sessionId in the path.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: fcf46c79

function sessionPath(sessionId?: string): string {
if (!sessionId)
return '';
if (!/^[\w-]+$/.test(sessionId))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ WARNING · Code Quality

With RPC bindings, connect() passes the session ID to connectSession() before checking it, in both packages.

In connect() (line ~167), RPC bindings call binding.connectSession!(options.sessionId) before connectDevtools runs this check. Puppeteer has the same order: connectSession(sessionId) in PuppeteerWorkers.ts runs before the check in WorkersWebSocketTransport.create. A malformed ID such as ../x therefore reaches the binding's RPC call unchecked and is only rejected afterwards. Check the ID at the start of connect() in both packages, for example by calling sessionPath(options.sessionId) there, and add a test that uses an RPC-style binding.

connect() and endpointURLString() reject malformed session IDs.
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

@cloudflare/playwright-mcp preview for commit 3adebf7

npm i https://pkg.pr.new/cloudflare/browser-run/@cloudflare/playwright-mcp@3adebf70cc39333f739b670db4ffbb103c71bf7d

Published by this workflow run. New pushes and reruns update this comment.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

@cloudflare/playwright preview for commit 3adebf7

npm i https://pkg.pr.new/cloudflare/browser-run/@cloudflare/playwright@3adebf70cc39333f739b670db4ffbb103c71bf7d

Published by this workflow run. New pushes and reruns update this comment.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

@cloudflare/puppeteer preview for commit 3adebf7

npm i https://pkg.pr.new/cloudflare/browser-run/@cloudflare/puppeteer@3adebf70cc39333f739b670db4ffbb103c71bf7d

Published by this workflow run. New pushes and reruns update this comment.

connect() now checks the session ID before it calls connectSession() on
an RPC binding. Before, a malformed ID reached the binding and failed
only later, in the devtools URL check. Puppeteer shares the check through
assertValidSessionId().

beep-boop-🤖
@ruifigueira
ruifigueira force-pushed the rfigueira/session-id-validation branch from fcf46c7 to 3adebf7 Compare November 24, 2026 09:44

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — No findings. Both packages now check the session ID before connectSession(), and new tests with an RPC-style binding cover that path.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

Every path that puts the session ID into the devtools URL now accepts only IDs that match /^[\w-]+$/, a single path segment. This rejects .., /, ? and trailing newlines. Puppeteer's browser branch skips the check, but that branch does not put the session ID in the path, so this is safe.


📋 Code Quality: ✅ LGTM

🔄 Since last review: 1 finding resolved, 0 preserved, 0 new.

  • Playwright: connect() now calls assertValidSessionId(options.sessionId) before binding.connectSession! (packages/playwright-cloudflare/src/index.ts:166).
  • Puppeteer: PuppeteerWorkers.connect() now checks the ID before it calls connectSession (PuppeteerWorkers.ts:255).
  • Tests: the new specs use an RPC-style binding and assert that connectSession is never called for a malformed ID.

📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: 3adebf70

@ruifigueira
ruifigueira merged commit d1da000 into main Nov 25, 2026
11 of 12 checks passed
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.

1 participant