Headline
CVE-2022-31015: Bugfix: Don't close socket in the WSGI thread, delegate it back to the main thread! by bertjwregeer · Pull Request #377 · Pylons/waitress
Waitress is a Web Server Gateway Interface server for Python 2 and 3. Waitress versions 2.1.0 and 2.1.1 may terminate early due to a thread closing a socket while the main thread is about to call select(). This will lead to the main thread raising an exception that is not handled and then causing the entire application to be killed. This issue has been fixed in Waitress 2.1.2 by no longer allowing the WSGI thread to close the socket. Instead, that is always delegated to the main thread. There is no work-around for this issue. However, users using waitress behind a reverse proxy server are less likely to have issues if the reverse proxy always reads the full response.
There’s a potential issue whereby a thread attempts to send data, but the socket is closed on the other end, and the thread shuts the socket down.
This may however happen while the file descriptors are being put together before being passed to select() which will then fail as that file descriptor is no longer valid.
Instead we loop until we have called select() successfully, while checking to see if the file descriptors has changed since we started the poll.
If the map of file descriptors has not changed, and yet we get an errno that is a bad file descriptor, we will just raise it and kill the main loop.
Closes #374
Related news
### Impact Waitress may terminate early due to a thread closing a socket while the main thread is about to call select(). This will lead to the main thread raising an exception that is not handled and then causing the entire application to be killed. ### Patches This issue has been fixed in Waitress 2.1.2 by no longer allowing the WSGI thread to close the socket, instead it is always delegated to the main thread. ### Workarounds There is no work-around, however users using waitress behind a reverse proxy server are less likely to have issues if the reverse proxy always reads the full response. ### For more information If you have any questions or comments about this advisory: * Open an issue in https://github.com/Pylons/waitress/issues (if not sensitive or security related) * email the Pylons Security mailing list: [[email protected]](mailto:[email protected]) (if security related)