The vulnerability stems from a lack of trust validation in JupyterLab's command execution mechanism. The CommandLinker feature was designed to allow HTML elements, like buttons, to trigger JupyterLab commands. However, it did so indiscriminately for any element in the DOM, including untrusted content rendered from notebook outputs.
The analysis of the patch reveals two key functions involved. The primary vulnerable function is CommandLinker._evtClick in packages/apputils/src/commandlinker.ts. This function is the event handler that listens for clicks and executes commands. Before the patch, it performed no checks to determine if the clicked element was from a trusted part of the UI or from potentially malicious user-provided output.
Aiding this vulnerability was the Sanitizer.sanitize function in packages/apputils/src/sanitizer.ts. By default, it allowed the data-commandlinker-* attributes necessary to trigger commands, meaning that even after sanitization, malicious HTML embedded in a notebook could retain its ability to execute commands.
The patch addresses this by introducing a trust boundary system. The CommandLinker._evtClick function was modified to first check if the clicked element resides within a trusted part of the DOM using a new _isTrusted method. If the element is not trusted, JupyterLab now prompts the user with a security warning before executing the command, thus preventing the one-click exploit. The sanitizer was also updated to allow for disabling the command linker attributes entirely as a hardening measure.