Repository navigation
fix: validate session IDs - #265
Conversation
There was a problem hiding this comment.
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 toconnectSession()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) callsbinding.connectSession!(options.sessionId)first. The check runs later, insideconnectDevtoolsthroughsessionPath(). - Puppeteer has the same order.
PuppeteerWorkers.tscallsconnectSession(sessionId)beforeWorkersWebSocketTransport.create, and the check lives increate. - So a malformed ID such as
..ora/breaches 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, beforeconnectSession(). In playwright, callingsessionPath(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)) |
There was a problem hiding this comment.
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.
|
npm i https://pkg.pr.new/cloudflare/browser-run/@cloudflare/playwright-mcp@3adebf70cc39333f739b670db4ffbb103c71bf7dPublished by this workflow run. New pushes and reruns update this comment. |
|
npm i https://pkg.pr.new/cloudflare/browser-run/@cloudflare/playwright@3adebf70cc39333f739b670db4ffbb103c71bf7dPublished by this workflow run. New pushes and reruns update this comment. |
|
npm i https://pkg.pr.new/cloudflare/browser-run/@cloudflare/puppeteer@3adebf70cc39333f739b670db4ffbb103c71bf7dPublished 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-🤖
fcf46c7 to
3adebf7
Compare
There was a problem hiding this comment.
✅ 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 callsassertValidSessionId(options.sessionId)beforebinding.connectSession!(packages/playwright-cloudflare/src/index.ts:166). - Puppeteer:
PuppeteerWorkers.connect()now checks the ID before it callsconnectSession(PuppeteerWorkers.ts:255). - Tests: the new specs use an RPC-style binding and assert that
connectSessionis never called for a malformed ID.
📝 Documentation: ✅ LGTM
No documentation issues.
Reviewed commit: 3adebf70
connect()andendpointURLString()reject malformed session IDs.