Waitress is a Web Server Gateway Interface server for Python 2 and 3. When a remote client closes the connection before waitress has had the opportunity to call getpeername() waitress won't correctly clean up the connection leading to the main thread attempting to write to a socket that no longer exists, but not removing it from the list of sockets to attempt to process. This leads to a busy-loop calling the write function. A remote attacker could run waitress out of available sockets with very little resources required. Waitress 3.0.1 contains fixes that remove the race condition.
Waitress is a Web Server Gateway Interface server for Python 2 and 3. A remote client may send a request that is exactly recvbytes (defaults to 8192) long, followed by a secondary request using HTTP pipelining. When request lookahead is disabled (default) we won't read any more requests, and when the first request fails due to a parsing error, we simply close the connection. However when request lookahead is enabled, it is possible to process and receive the first request, start sending the error message back to the client while we read the next request and queue it. This will allow the secondary request to be serviced by the worker thread while the connection should be closed. Waitress 3.0.1 fixes the race condition. As a workaround, disable channelrequestlookahead, this is set to 0 by default disabling this feature.
Impact
A remote client may send a request that is exactly recvbytes (defaults to 8192) long, followed by a secondary request using HTTP pipelining.
When request lookahead is disabled (default) we won't read any more requests, and when the first request fails due to a parsing error, we simply close the connection.
However when request lookahead is enabled, it is possible to process and receive the first request, start sending the error message back to the client while we read the next request and queue it. This will allow the secondary request to be serviced by the worker thread while the connection should be closed.
Patches
Waitress 3.0.1 fixes the race condition.
Workarounds
Disable channelrequestlookahead, this is set to 0 by default disabling this feature. For this vulnerability this value is required to be changed from the default.
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: pylons-project-security@googlegroups.com (if security related)
Thanks
- m4yfly and urn1ce From TianGong Team of Legendsec at Qi'anxin Group.
Impact
When a remote client closes the connection before waitress has had the opportunity to call getpeername() waitress won't correctly clean up the connection leading to the main thread attempting to write to a socket that no longer exists, but not removing it from the list of sockets to attempt to process. This leads to a busy-loop calling the write function.
A remote attacker could run waitress out of available sockets with very little resources required.
Patches
Waitress 3.0.1 contains fixes that remove the race condition.
Workarounds
No work-around.
References
- https://github.com/Pylons/waitress/issues/418 - https://github.com/Pylons/waitress/pull/435
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: pylons-project-security@googlegroups.com (if security related)
Impact
When using Waitress behind a proxy that does not properly validate the incoming HTTP request matches the RFC7230 standard, Waitress and the frontend proxy may disagree on where one request starts and where it ends.
This would allow requests to be smuggled via the front-end proxy to waitress and later behavior.
There are two classes of vulnerability that may lead to request smuggling that are addressed by this advisory:
- The use of Python's int() to parse strings into integers, leading to +10 to be parsed as 10, or 0x01 to be parsed as 1, where as the standard specifies that the string should contain only digits or hex digits. - Waitress does not support chunk extensions, however it was discarding them without validating that they did not contain illegal characters
Patches
This has been fixed in Waitress 2.1.1
Workarounds
When deploying a proxy in front of waitress, turning on any and all functionality to make sure that the request matches the RFC7230 standard. Certain proxy servers may not have this functionality though and users are encouraged to upgrade to the latest version of waitress instead.
References
- https://portswigger.net/research/http-desync-attacks-request-smuggling-reborn
For more information
If you have any questions or comments about this advisory: Open an issue in the Github issue tracker (if not security related/sensitive) Email us at pylons-project-security@googlegroups.com (If security related or sensitive)
Waitress through version 1.3.1 allows request smuggling by sending the Content-Length header twice. Waitress would header fold a double Content-Length header and due to being unable to cast the now comma separated value to an integer would set the Content-Length to 0 internally. If two Content-Length headers are sent in a single request, Waitress would treat the request as having no body, thereby treating the body of the request as a new request in HTTP pipelining. This issue is fixed in Waitress 1.4.0.
Impact
The patches introduced to fix https://github.com/Pylons/waitress/security/advisories/GHSA-m5ff-3wj3-8ph4 were not complete and still would allow an attacker to smuggle requests/split a HTTP request with invalid data.
This updates the existing CVE with ID: CVE-2019-16789
Patches
Waitress version 1.4.2 has been updated to now validate HTTP headers better to avoid the issue, completely fixing all known issues with whitespace.
Workarounds
There are no work-arounds, upgrading to Waitress 1.4.2 is highly recommended.
References
See https://github.com/Pylons/waitress/security/advisories/GHSA-m5ff-3wj3-8ph4 for more information on the security issue.
For more information
If you have any questions or comments about this advisory:
open an issue at https://github.com/Pylons/waitress/issues (if not sensitive or security related) email the Pylons Security mailing list: pylons-project-security@googlegroups.com (if security related)
Impact
Waitress would parse the Transfer-Encoding header and only look for a single string value, if that value was not chunked it would fall through and use the Content-Length header instead.
According to the HTTP standard Transfer-Encoding should be a comma separated list, with the inner-most encoding first, followed by any further transfer codings, ending with chunked.
Requests sent with:
Transfer-Encoding: gzip, chunked
Would incorrectly get ignored, and the request would use a Content-Length header instead to determine the body size of the HTTP message.
This could allow for Waitress to treat a single request as multiple requests in the case of HTTP pipelining.
Patches
This issue is fixed in Waitress 1.4.0. This brings a range of changes to harden Waitress against potential HTTP request confusions, and may change the behaviour of Waitress behind non-conformist proxies.
Waitress will now return a 501 Not Implemented error if the Transfer-Encoding is not chunked or contains multiple elements. Waitress does not support any transfer codings such as gzip or deflate.
The Pylons Project recommends upgrading as soon as possible, while validating that the changes in Waitress don't cause any changes in behavior.
Workarounds
Various reverse proxies may have protections against sending potentially bad HTTP requests to the backend, and or hardening against potential issues like this. If the reverse proxy doesn't use HTTP/1.1 for connecting to the backend issues are also somewhat mitigated, as HTTP pipelining does not exist in HTTP/1.0 and Waitress will close the connection after every single request (unless the Keep Alive header is explicitly sent... so this is not a fool proof security method).
Issues/more security issues:
open an issue at https://github.com/Pylons/waitress/issues (if not sensitive or security related) email the Pylons Security mailing list: pylons-project-security@googlegroups.com (if security related)
Impact
Waitress implemented a "MAY" part of the RFC7230 (https://tools.ietf.org/html/rfc7230#section-3.5) which states:
Although the line terminator for the start-line and header fields is the sequence CRLF, a recipient MAY recognize a single LF as a line terminator and ignore any preceding CR.
Unfortunately if a front-end server does not parse header fields with an LF the same way as it does those with a CRLF it can lead to the front-end and the back-end server parsing the same HTTP message in two different ways. This can lead to a potential for HTTP request smuggling/splitting whereby Waitress may see two requests while the front-end server only sees a single HTTP message.
Example:
Content-Length: 100[CRLF] X-Header: x[LF]Content-Length: 0[CRLF]
Would get treated by Waitress as if it were:
Content-Length: 100 X-Header: x Content-Length: 0
This could potentially get used by attackers to split the HTTP request and smuggle a second request in the body of the first.
Patches
This issue is fixed in Waitress 1.4.0. This brings a range of changes to harden Waitress against potential HTTP request confusions, and may change the behaviour of Waitress behind non-conformist proxies.
Waitress no longer implements the MAY part of the specification and instead requires that all lines are terminated correctly with CRLF. If any lines are found with a bare CR or LF a 400 Bad Request is sent back to the requesting entity.
The Pylons Project recommends upgrading as soon as possible, while validating that the changes in Waitress don't cause any changes in behavior.
Workarounds
Various reverse proxies may have protections against sending potentially bad HTTP requests to the backend, and or hardening against potential issues like this. If the reverse proxy doesn't use HTTP/1.1 for connecting to the backend issues are also somewhat mitigated, as HTTP pipelining does not exist in HTTP/1.0 and Waitress will close the connection after every single request (unless the Keep Alive header is explicitly sent... so this is not a fool proof security method)
Issues/more security issues:
open an issue at https://github.com/Pylons/waitress/issues (if not sensitive or security related) email the Pylons Security mailing list: pylons-project-security@googlegroups.com (if security related)