The vulnerability is a bypass of the Cross-Origin Resource Sharing (CORS) origin validation in Jupyter Server. The allow_origin_pat setting is intended to be a regex pattern to validate the Origin header of incoming requests. However, the server was using Python's re.match() function for this validation. re.match() only checks for a match at the beginning of the string, not the entire string.
This means if allow_origin_pat was set to, for example, https://trusted.example.com, an attacker could register a domain like https://trusted.example.com.evil.com and it would pass the validation, as re.match() would find a match at the start of the string. This would allow the attacker's malicious site to make cross-origin requests to the Jupyter server, potentially leading to the execution of unauthorized code or theft of sensitive data.
The patch replaces re.match() with re.fullmatch() (wrapped in a helper function _origin_matches_pat and later origin_matches_pat). re.fullmatch() ensures that the entire Origin header string matches the pattern, thus preventing this bypass.
The vulnerable functions are those that were performing this flawed origin check. The analysis of the patch commits reveals that the check was performed in multiple handlers:
LoginHandler._redirect_safe: when handling login redirects.
JupyterHandler.set_cors_headers: when setting CORS headers for a request.
JupyterHandler.check_origin: when checking the origin for a standard request.
JupyterHandler.check_referer: when checking the referer header.
WebSocketMixin.check_origin: when checking the origin for a WebSocket connection.
An exploit would involve a user visiting a malicious website which then makes cross-origin requests to a vulnerable Jupyter Server instance. The profiler on the server would show calls to one of the identified vulnerable functions, which would incorrectly grant access to the malicious origin.