68 Commits

Author SHA1 Message Date
Benoit Chesneau
8fa57d0884
Merge pull request #2928 from samypr100/pycodestyle-fixup
Fixing errors reported by pycodestyle
2023-01-26 22:34:51 +01:00
samypr100
2ea4699fe7
Fixing errors reported by pycodestyle 2023-01-22 21:20:11 -05:00
benoitc
30baeebf33
Revert "get address from tuple"
This reverts commit c9d01c801967596f66636cfc0c47660339d32631.
2023-01-22 12:47:07 -05:00
focus zheng
c9d01c8019 get address from tuple 2022-07-14 10:19:18 +08:00
focus zheng
69bf1d0cf4 remove changes by isort and lint 2022-07-13 15:44:30 +08:00
Randall Leeds
3573fd38d0 Capture peer name from accept
Avoid calls to getpeername by capturing the peer name returned by
accept.
2020-12-17 22:13:02 -05:00
Benoit Chesneau
b3f9815aba fix: don't enforce the content length
we were trying to enforce the content length when the websocket
key was received but we should instead rely on the headers provided in
the request. Enforcing the expectation of the content length should be
done by the client side not by us.

Changes:

* remove content-length header enforcing in message.p when the
"Sec-WebSocket-Key1" header was found
2020-08-26 10:56:04 +02:00
Takuya Noguchi
ed901637ff Enable pycodestyle 2019-11-28 19:30:38 +09:00
benoitc
0d8a022791 Revert "fix wsgi.input_terminated"
This reverts commit 265e58f9e82f64e003015fb25823f5a983be8c27.
2019-11-21 18:11:17 +01:00
benoitc
265e58f9e8 fix wsgi.input_terminated
Sometimes both TRANSFER-ENCODING=chunked and CONTENT_LENGTH are set. Since gunicorn prioritise (following the HTTP1.1 spec) chunked encoding we should make sure in this case to signal to th application that the input is terminated by the server.

Without the change gunicorn were always setting wsg.input_terminated to False when a CONTENT_LENGTH header was present ignoring that Gunicorn was afaik handling the termination.
2019-11-20 23:07:14 +01:00
Emile Fugulin
ddf5e66ac8 Remove strict check of Transfer-Encoding 2019-11-20 12:25:39 -05:00
Emile Fugulin
f74324bd75 Handle multiple transfer-encoding 2019-11-18 22:29:02 -05:00
Emile Fugulin
bd8670b4db Handle duplicate content-length 2019-11-18 21:16:12 -05:00
Emile Fugulin
b798412444 Remove default strip of header name 2019-11-18 19:44:01 -05:00
Hasan Ramezani
e7890d8d1b
Fix lint errors (#2123) 2019-10-27 11:57:16 +01:00
Marat
a8963ef1a5 Remove redundant super() arguments 2019-03-16 15:00:07 -07:00
Randall Leeds
e179dc2575 Support str and bytes for UNIX socket addresses (#1882)
Some systems report UNIX socket addresses as bytes while others will
report it as a unicode string type. This patch improves socket type
detection code to support both.

Fix #1861
2018-09-24 08:57:53 +02:00
Hugo
e974f30517 Drop support for Python 2
Co-Authored-By: Dustin Ingram <di@users.noreply.github.com>
Co-Authored-By: Berker Peksag <berker.peksag@gmail.com>
2018-08-01 15:31:17 +03:00
Randall Leeds
b9c4f893ad Fix secure scheme headers for UNIX sockets 2018-04-30 11:11:44 -07:00
Berker Peksag
76eaa0805b Fix various warnings and errors reported by pylint 2018-01-11 09:59:31 +03:00
Randall Leeds
b07532be75 Forbid contradictory secure scheme headers
When a request specifies contradictory secure scheme headers, raise a
parse error.
2018-01-10 12:10:35 -08:00
YuppY
5953148573 Do not strip leading slash from path (#1511)
Fixes #1512
2017-12-28 11:32:47 +03:00
Randall Leeds
cb2f471831 Remove superfluous BytesIO allocation 2017-12-10 11:57:32 -08:00
Raphaël Slinckx
15e901a5e5 http/message: Split request line as bytes to avoid splitting on 0x0A. Fixes #1577 2017-08-25 10:50:34 +02:00
Benno Rice
0d11691718 Ensure that overriding methods match the signature they've overriden. 2017-07-12 16:34:28 +03:00
Benno Rice
032271a030 Empty sequences are false, there's no need to check the len. 2017-07-12 16:15:42 +03:00
Your Name
a912e305c9 Reject requests like "GET / HTTP/1a1"
Numbers must be separated by dot. This makes life
a little bit harder for attackers who would like to inject specially crafted packets after GET / (e.g. in nginx there are sometimes regular expressions like (?P<action>[^.]).html
2016-11-04 21:16:01 +03:00
Tobias Gustafsson
70cfb0d818 Remove upper limit on max header size config (#1313)
Fixes #1306
2016-09-17 12:49:05 +03:00
Berker Peksag
95b5f78ecb Backport urlparse.urlsplit from Python 2.7 to Python 2.6.
urlsplit doesn't reject invalid IPv6 addresses in Python 2.6.
2015-05-10 10:40:32 +03:00
Berker Peksag
b951175c66 Raise InvalidRequestLine instead of ValueError if the line contains malicious data.
Closes #1023
2015-05-09 19:12:58 +03:00
Collin Anderson
f2ba62bc10 six 1.8.0 and gunicorn._compat
closes #904 and #905
2014-10-02 17:00:03 -04:00
Benoit Chesneau
26a796f200 Merge pull request #670 from gnotaras/bugfix-request-line-check
Fixed the request line length check.
2014-01-01 07:48:44 -08:00
George Notaras
b9fe01ca2c Fixed the request line length check. 2013-12-19 03:18:18 +02:00
Neil Williams
9d9e547316 proxy_allow_ips: Allow proxy protocol if "*" specified.
This makes proxy_allow_ips symmetrical with forwarded_allow_ips and is
useful in the same situations.
2013-12-17 13:48:27 -08:00
Alex Gaynor
b5c1810722 Only compiled some regexes used in HTTP parsing once
Currently they are parsed and compiled once per-HTTP request, which is
unnescary computation and makes stuff slower than it could be.
2013-08-28 20:23:53 -07:00
Adnane Belmadiaf
20cd49595a PEP8 fixes 2012-12-24 09:53:03 +01:00
benoitc
8d453fb341 all tests pass under python 3 2012-10-24 22:07:35 +02:00
benoitc
003c474fe2 handle bytes & native strings
This patch makes sure that we now handle correctly bytes and native
strings on python 3:

- In python 3, sockets are now taking and returning bytes.
- according to PEP3333, headers should be native strings and body in
  bytes.
2012-10-24 13:51:35 +02:00
benoitc
53ce50bc7b obvious syntax fixes preparing python3 support 2012-10-24 12:11:15 +02:00
Konstantin Kapustin
70534acde8 Implantation proxy protocol 2012-09-27 19:14:40 +02:00
Konstantin Kapustin
4be3282440 Check Content-Length header.
For not chunked request do validation Content-Length header and return 400 if invalid.
2012-09-27 19:14:40 +02:00
Konstantin Kapustin
4fdfc3a76b Fix LimitRequestLine check. 2012-08-20 16:02:52 +04:00
benoitc
4b478e1a66 fix request line check. close #390
We never had the possibility to check the limit since we were quitting
the loop before it.
2012-08-03 06:27:26 +02:00
Paul J. Davis
489e935038 Fix request line length check
We were accidentally including partial data when we didn't find the
request line terminating '\r\n'. This changes the check to make sure
we're testing the length after we assert there's no termination.
2012-07-04 15:53:10 -05:00
benoitc
ffecd64669 don't finish the loop if the headers length is too big 2012-05-25 12:27:40 +02:00
benoitc
d79ff999ce fix multiple issues with request limit
patch from Djoume Salvetti . address the following issues in gunicorn:

* Gunicorn does not limit the size of a request header (the
* limit_request_field_size configuration parameter is not used)

* When the configured request limit is lower than its maximum value, the
* maximum value is used instead. For instance if limit_request_line is
* set to 1024, gunicorn will only limit the request line to 4096 chars
* (this issue also affects limit_request_fields)

* Request limits are not limited to their maximum authorized values. For
* instance it is possible to set limit_request_line to 64K (this issue
* also affects limit_request_fields)

* Setting limit_request_fields and limit_request_field_size to 0 does
* not make them unlimited. The following patch allows limit_request_line
* and limit_request_field_size to be unlimited. limit_request_fields can
* no longer be unlimited (I can't imagine 32K fields to not be enough
* but I have a use case where 8K for the request line is not enough).

* Parsing errors (premature client disconnection) are not reported

* When request line limit is exceeded the configured value is reported
* instead of the effective value.
2012-05-24 12:13:34 +02:00
benoitc
86ea0c6f8d remove this buggy & useless check 2012-02-25 15:14:11 +01:00
benoitc
7a1c58f236 test number of headers fields and size.
Add --limit-request-fields (limit_request_fields) and
--limit-request-field-size (limit-request-field-size) options.

- limit_request_fields:

    Value is a number from 0 (unlimited) to 32768. This parameter is
    used to limit the number of headers in a request to prevent DDOS
    attack. Used with the `limit_request_field_size` it allows more
    safety.

- limit_request_field_size:

    Value is a number from 0 (unlimited) to 8190. to set the limit
    on the allowed size of an HTTP request header field.
2012-02-20 10:36:13 +01:00
benoitc
b7b0979ad9 check if Request Line is too large.
You can now pass the parameter --limit-request-line or set the
limit_request_line in your configuration file to set the max size of the
request line in bytes.

This parameter is used to limit the allowed size of a client's HTTP
request-line. Since the request-line consists of the HTTP method, URI,
and protocol version, this directive places a restriction on the length
of a request-URI allowed for a request on the server. A server needs
this value to be large enough to hold any of its resource names,
including any information that might be passed in the query part of a
GET request. By default this value is 4094 and can't be larger than
8190.

This parameter can be used to prevent any DDOS attack.
2012-02-20 09:56:06 +01:00
benoitc
6766c14793 pass config to the http parser. 2012-02-20 07:02:55 +01:00