The vulnerability is a buffer over-read in the websocket_mask function located in Tornado's C extension, tornado.speedups. This function is used for unmasking websocket frames but is also leveraged by the XSRF token decoding mechanism.
The root cause is that the C implementation of websocket_mask unconditionally reads 4 bytes from the mask parameter, without first verifying that the provided buffer is at least 4 bytes long.
An attacker can trigger this by providing a crafted _xsrf cookie. When the application calls check_xsrf_cookie() (or any method that triggers it, like decode_signed_value with xsrf_cookies=True), the _decode_xsrf_token method is called. This method base64-decodes the cookie and uses the first 4 bytes as the mask for the websocket_mask function. If the decoded cookie value is less than 4 bytes, the call to websocket_mask results in reading beyond the buffer's boundary, exposing adjacent memory contents.
The patch mitigates this by adding a length check at the beginning of both the C function websocket_mask in tornado/speedups.c and its Python fallback _websocket_mask_python in tornado/util.py, ensuring the mask is exactly 4 bytes long.
Therefore, the key function to monitor is speedups.websocket_mask, as it's the one containing the memory corruption vulnerability. The Python fallback _websocket_mask_python is also relevant as it was patched defensively.