Skip to content

[WebDriver][BiDi] Distinguish static and session-bound commands - #75649

Open
sergedeh wants to merge 1 commit into
WebKit:mainfrom
sergedeh:eng/WebDriver-BiDi-Distinguish-static-and-session-bound-commands
Open

sergedeh wants to merge 1 commit into
WebKit:mainfrom
sergedeh:eng/WebDriver-BiDi-Distinguish-static-and-session-bound-commands

Conversation

@sergedeh

@sergedeh sergedeh commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

[WebDriver][BiDi] Distinguish static and session-bound commands
https://bugs.webkit.org/show_bug.cgi?id=281721

Reviewed by NOBODY (OOPS!).

Classify incoming BiDi commands before requiring the connection to have an associated session. Handle static session.status commands locally, reject known session-bound commands with invalid session id when no session is associated, and reject unknown methods with unknown command.

Generate the session-bound command catalog from WebKit's current BiDi protocol schemas instead of maintaining a second manual list. Admit connections to the default /session resource, preserve the incoming connection on responses, and make connection cleanup safe when no session exists. WebDriverBidiProcessor remains unchanged and receives only commands that pass the session gate.

Regression coverage for static, session-bound, and unknown commands without an active session is submitted upstream in
web-platform-tests/wpt#63212 and was exercised locally with WebKitWebDriver.

  • Source/WebDriver/CMakeLists.txt: Generate the session-bound BiDi command-name header from the protocol schemas.
  • Source/WebDriver/WebDriverService.cpp: (WebDriver::WebDriverService::s_staticBidiCommands): Rename the local table to state that it contains static commands.
    (WebDriver::WebDriverService::acceptHandshake): Admit connections to /session without requiring an active session and make session-specific validation null-safe.
    (WebDriver::WebDriverService::handleMessage): Distinguish static, session-bound, and unknown commands before applying the session gate. (WebDriver::WebDriverService::findStaticBidiCommand): Look up a static command descriptor by method name.
    (WebDriver::WebDriverService::clientDisconnected): Clean up unassociated connections without dereferencing the current session.
  • Source/WebDriver/WebDriverService.h: Rename the local command descriptor and lookup to identify their static scope.
  • Source/WebKit/Scripts/generate-webdriver-bidi-command-names.py: Added. (parse_arguments): Parse the output and protocol schema paths. (command_names): Collect and validate fully qualified command names. (generate_header): Generate the sorted command-name set. (main): Write the generated header.
    316e9d2
Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 webkitpy ✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-debug
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk3-gcc
✅ 🛠 ios-safer-cpp ✅ 🧪 mac-AS-debug-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-intel-wk2 ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🛠 mac-safer-cpp   🛠 playstation
✅ 🛠 tv ✅ 🧪 mac-site-isolation
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@sergedeh
sergedeh marked this pull request as ready for review October 2, 2026 12:13
@sergedeh
sergedeh force-pushed the eng/WebDriver-BiDi-Distinguish-static-and-session-bound-commands branch from e086e4b to b92b12f Compare October 2, 2026 20:48

@burg burg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

r=me

Comment thread Source/WebDriver/CMakeLists.txt Outdated
)

if (ENABLE_WEBDRIVER_BIDI)
set(WebDriver_BIDI_PROTOCOL_INPUTS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is another instance of the list in Source/WebKit/CMakeLists.txt, DerivedSources.make and DerivedSources-input.xcfilelist, and it has already drifted. BidiInput.json landed on main last week (7f43fa7) and isn't here, so after a rebase every input.* command gets unknown command from WebKitWebDriver instead of being relayed. There's no build error when that happens, which is what worries me.

Followup: can we keep one source of truth? Either a shared include that both directories read, or have the generator read the already combined CombinedWebDriverBidiDomains.json, which also gets condition filtering for free.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i have picked the generator using the CombinedWebDriverBidiDomains.json

Comment thread Source/WebDriver/WebDriverService.cpp Outdated
RELEASE_LOG(WebDriverBiDi, "BiDi-only sessions are not supported yet. Rejecting handshake.");
return false;
}
if (*foundResource == "/session"_s)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Now that /session handshakes are accepted, any page on the machine can open a socket to the driver (browsers don't apply CORS to WebSockets), and as far as I can tell we don't check Origin or Host anywhere in the soup handshake. Today that only exposes session.status, but once session.new lands in #75992 it becomes a way to create and drive a session. I'm going to ask for the check on that PR, but if it's easier to do here in acceptHandshake, even better.

Nit: the // FIXME Add support for bidi-only sessions went away with nothing replacing it. If this lands well before #75992, please put back a FIXME pointing at https://bugs.webkit.org/show_bug.cgi?id=281722, since session.new on this connection currently says "Unknown command".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i have added a patch for handshake validation #77457

@sergedeh
sergedeh force-pushed the eng/WebDriver-BiDi-Distinguish-static-and-session-bound-commands branch from b92b12f to c6a64a4 Compare October 17, 2026 16:54
@sergedeh
sergedeh force-pushed the eng/WebDriver-BiDi-Distinguish-static-and-session-bound-commands branch from c6a64a4 to 61c473b Compare October 18, 2026 18:37
https://bugs.webkit.org/show_bug.cgi?id=281721

Reviewed by NOBODY (OOPS!).

Classify incoming BiDi commands before requiring the connection to have an
associated session. Handle static session.status commands locally, reject
known session-bound commands with invalid session id when no session is
associated, and reject unknown methods with unknown command.

Generate the session-bound command catalog from WebKit's combined BiDi
protocol schema instead of maintaining a second protocol-file list. This keeps
classification in sync with the domains used by WebKit's BiDi backend and
automatically includes newly added domains such as input. Admit connections to
the default /session resource, preserve the incoming connection on responses,
and make connection cleanup safe when no session exists. WebDriverBidiProcessor
remains unchanged and receives only commands that pass the session gate.

Regression coverage for static, session-bound, and unknown commands without
an active session is submitted upstream in
web-platform-tests/wpt#63212 and was exercised locally
with WebKitWebDriver.

* Source/WebDriver/CMakeLists.txt:
Generate the session-bound BiDi command-name header from WebKit's existing
combined BiDi protocol schema.
* Source/WebDriver/WebDriverService.cpp:
(WebDriver::WebDriverService::s_staticBidiCommands): Rename the local table to
state that it contains static commands.
(WebDriver::WebDriverService::acceptHandshake): Admit connections to /session
without requiring an active session and make session-specific validation
null-safe.
(WebDriver::WebDriverService::handleMessage): Distinguish static,
session-bound, and unknown commands before applying the session gate.
(WebDriver::WebDriverService::findStaticBidiCommand): Look up a static command
descriptor by method name.
(WebDriver::WebDriverService::clientDisconnected): Clean up unassociated
connections without dereferencing the current session.
* Source/WebDriver/WebDriverService.h:
Rename the local command descriptor and lookup to identify their static scope.
* Source/WebKit/Scripts/generate-webdriver-bidi-command-names.py: Added.
(parse_arguments): Parse the output and combined protocol schema paths.
(command_names): Collect and validate fully qualified command names from the
combined schema's domains.
(generate_header): Generate the sorted command-name set.
(main): Write the generated header.
@sergedeh
sergedeh force-pushed the eng/WebDriver-BiDi-Distinguish-static-and-session-bound-commands branch from 61c473b to 316e9d2 Compare October 18, 2026 19:16
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.

3 participants