201 Commits

Author SHA1 Message Date
Paul J. Dorn
184e36f9da skip eventlet, not yet supported on python 3.12
will work again,
should still be reverted when stdlib conflict resolved in eventlet
2023-12-29 05:11:18 +01:00
Paul J. Dorn
e710393d14 HTTP parser: stricter chunk-ext OBS handling
chunk extensions are silently ignored before and after this change;
its just the whitespace handling for the case without extensions that matters
applying same strip(WS)->rstrip(BWS) replacement as already done in related cases

half-way fix: could probably reject all BWS cases, rejecting only misplaced ones
2023-12-17 17:46:56 +01:00
Paul J. Dorn
7ebe442d08 strict HTTP version validation
Note: This is unrelated to a reverse proxy potentially talking HTTP/3 to clients.
This is about the HTTP protocol version spoken to Gunicorn, which is HTTP/1.0 or HTTP/1.1.

Little legitimate need for processing HTTP 1 requests with ambiguous version numbers.
Broadly refuse.

Co-authored-by: Ben Kallus <benjamin.p.kallus.gr@dartmouth.edu>
2023-12-15 13:33:31 +01:00
Paul J. Dorn
f5501111a2 strict HTTP header field name validation
Do the validation on the original, not the result from unicode case folding.

Background:
latin-1 0xDF is traditionally uppercased 0x53+0x53 which puts it back in ASCII
2023-12-15 13:33:31 +01:00
Paul J. Dorn
ac29c9b0a7 fail-safe on unsupported request framing
If we promise wsgi.input_terminated, we better get it right - or not at all.
* chunked encoding on HTTP <= 1.1
* chunked not last transfer coding
* multiple chinked codings
* any unknown codings (yes, this too! because we do not detect unusual syntax that is still chunked)
* empty coding (plausibly harmless, but not see in real life anyway - refused, for the moment)
2023-12-15 13:33:31 +01:00
Paul J. Dorn
72b8970dbf silently drop or refuse header names w/ underscore
Ambiguous mappings open a bottomless pit of "what is user input and what is proxy input" confusion.
Default to what everyone else has been doing for years now, silently drop.

see also https://nginx.org/r/underscores_in_headers
2023-12-15 13:33:31 +01:00
Paul J. Dorn
b2846783d7 strict: header field validation: stop casefolding
* refusing lowercase and ASCII 0x23 (#) had been partially enforced before
* do not casefold by default, HTTP methods are case sensitive
2023-12-15 13:33:31 +01:00
Paul J. Dorn
42dd4190ac test: verify TOKEN_RE against common HTTP Methods 2023-12-15 13:33:31 +01:00
Ben Kallus
72238fcf8d RFC compliant request line and header parsing
- Unify HEADER_RE and METH_RE
- Replace CRLF with SP during obs-fold processing (See RFC 9112 Section 5.2, last paragraph)
- Stop stripping header names.
- Remove HTAB in OWS in header values that use obs-fold (See RFC 9112 Section 5.2, last paragraph)
- Use fullmatch instead of search, which has problems with empty strings. (See GHSA-68xg-gqqm-vgj8)
- Split proxy protocol line on space only. (See proxy protocol Section 2.1, bullet 3)
- Use fullmatch for method and version (Thank you to Paul Dorn for noticing this.)
- Replace calls to str.strip() with str.strip(' \t')
- Split request line on SP only.

Co-authored-by: Paul Dorn <pajod@users.noreply.github.com>
2023-12-15 13:33:31 +01:00
Paul J. Dorn
559caf9205 pytest: raise on malformed test fixtures
and unbreak test depending on backslash escape
2023-12-15 13:33:31 +01:00
Jason Myers
fa94f70529 Updating Content-Length Handling
Signed-off-by: Jason Myers <jmyers@syntellis.com>
2023-05-30 20:42:13 -05:00
unknown
48d670f087 update pylint version, and fix linter issues 2023-05-17 18:45:59 +03:00
Tero Saarni
d8c3b1490e Deprecate ssl_version option
This change defaults SSLContext to Python's ssl.create_default_context() and
marks ssl_version option as deprecated. The option value will be ignored and
warnign will be printed in stderr.

The ssl_version option was depending on old method of setting TLS min/max
version, which has not worked well anymore with modern Python versions.
2023-05-11 17:45:57 +03:00
Benoit Chesneau
4a1c402e2c
Merge pull request #2384 from larribas/2066-statsd-socket
Allow reporting StatsD metrics over UDS sockets
2023-05-07 20:39:11 +02:00
Christian Clauss
1feb7c59a2 Revert the xfail for Python 3.10 2022-02-07 08:23:03 +11:00
Christian Clauss
a16b8975a9 GitHub Action to run tox
Because Travis CI seems to be on vacation... https://travis-ci.org/github/benoitc/gunicorn
2022-02-07 08:23:03 +11: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
larribas
2a16fcd3ce Test and defend against the specific case where the statsd hostname is 'unix' 2020-07-20 10:16:42 +02:00
larribas
15abac7e81 Allow specifying a UDS socket address through --statsd-host 2020-07-19 20:11:09 +02:00
Hasan Ramezni
57a9e2eb7e Specify wsgi_app in config #1359. 2020-05-01 01:11:21 +02:00
Randall Leeds
839d5dc66c Merge pull request #1996 from javabrett/1690-rewritings 2020-04-20 15:37:41 -07:00
Randall Leeds
ee685e197b Merge pull request #2054 from rcoup/2052-print-config 2020-04-20 12:40:57 -07:00
Stanis Trendelenburg
27d1e9887a Fix issues #2133 and #2244
Start reloader after loading the WSGI app.
2020-02-02 22:57:14 +01:00
Jason Madden
2d40e6dace
Use socket.sendfile() instead of os.sendfile().
Fixes #2223.

Unfortunately, eventlet doesn't implement GreenSocket.sendfile, so we have to do it for it.

Add gevent and eventlet to tox.ini and add tests to make sure we can at least import the workers. Some tests that this actually functions would be nice...

Update the gevent and eventlet setup extras to require the versions that are enforced in their worker modules.
2020-01-04 06:31:25 -06:00
Aaron Wilson
291483dd39 Add a __repr__ to config to include its value (#2076)
It's sometimes helpful to be able to trivially dump all the config values
for debugging purposes. This commit defines a repr for that.
2019-11-22 21:39:45 +01:00
Benoit Chesneau
c5be1bae5c
Merge pull request #2181 from Sytten/fix/http-desync
Fix/http desync
2019-11-20 21:28:18 +01:00
Emile Fugulin
ddf5e66ac8 Remove strict check of Transfer-Encoding 2019-11-20 12:25:39 -05:00
David Lord
19cb68f4c3 load application from factory function (#2178)
* load application from factory function

Use `ast.parse` to validate that the string passed to the CLI is either
an attribute name or a function call. Use `ast.literal_eval` to parse
any positional and keyword arguments to the function. Call the function
to get the real application.

Co-authored-by: Connor Brinton <connor.brinton@gmail.com>

* test coverage for util.import_app

* document app factory pattern
2019-11-19 23:09:53 +01: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
Wojciech Malinowski
4b91ca1e9f Merge branch 'master' of github.com:benoitc/gunicorn into 2066-statsd-socket 2019-10-26 15:31:16 +02:00
Martin Bašti
f38f717539 Fix pytest 5.0.0 compatibility
pytest.raises() returns exception info not the exception itself. They
changed implementation of exception info, so now .value property must be
used to get the exception instance and have proper output from str()
method.

https://github.com/pytest-dev/pytest/issues/5412

Signed-off-by: Martin Bašti <mbasti@redhat.com>
2019-07-17 18:56:18 +03:00
Martin Bašti
7e640f804c Logging: Handle auth type case insensitively
According RFC-7617 (inherited from RFC-2978) schema and parameter names are handled
case insensitively:
```
Note that both scheme and parameter names are matched case-
insensitively.
```

Signed-off-by: Martin Bašti <mbasti@redhat.com>
2019-07-17 18:56:18 +03:00
Brett Randall
b014fa78ee Various code improvements contributed by dilyanpalauzov.
These were originally based on 19.9.0 code and were rebased
with conflicts resolved.

Fixed #1690.

Co-Authored-By: dilyanpalauzov <git-dpa@aegee.org>
Signed-off-by: Brett Randall <javabrett@gmail.com>
2019-07-17 07:32:11 +10:00
Wojciech Malinowski
5803f835f6 Added a possibility of logging the metrics to a Unix domain socket instead of UDP 2019-06-06 15:13:23 +02:00
Robert Coup
93d2687d24 f-strings only date back to Py3.6 2019-05-31 12:15:02 +01:00
Robert Coup
13c5d72bd1 Add --print-config option to print the resolved settings at startup. 2019-05-31 12:04:22 +01:00
Masashi SHIBATA
b15712924f Import unittest.mock unconditionally (#2050) 2019-05-28 16:09:44 +03:00
Masashi SHIBATA
c435341e66 Remove fallback for types.SimpleNamespace (#2049) 2019-05-28 16:05:51 +03:00
Masashi SHIBATA
a13a2096ed Use SourceFileLoader instead instead of execfile_ (#2046) 2019-05-26 22:09:52 +03:00
dblack
96dde54af1 optional datadog tags for statsd metrics 2019-04-27 18:49:47 -07:00
Brett Randall
879651bb6f Header values are encoded using latin-1, not ascii.
This commit reverts one aspect changed by 5f4ebd2eb2b08783a5fbefe79d09fcb3fc1fbc73 (#1151);
header-values are again encoded as latin-1 and not ascii. Test is restored but uses
a latin-1-mappable test-character, not a general utf8 character.

Fixed #1778.

Signed-off-by: Brett Randall <javabrett@gmail.com>
2019-04-18 04:23:19 +03:00
Hasan Ramezani
2b07f2be28 Rewrite parse_address util and add one test 2019-03-16 15:07:53 -07:00
Marat
a8963ef1a5 Remove redundant super() arguments 2019-03-16 15:00:07 -07:00
Benoit Chesneau
97a45805f8
remove gaiohttp worker (#1971)
* remove gaiohttp worker

worker is deprecated and won't work on latest version.
2019-01-24 23:05:28 +01:00
Daniel Pope
2ea5fbdc86 Use Python's default SSL cipher list by default (#1970) 2019-01-24 22:41:04 +01:00
Florian Apolloner
ee7af1247b Added support to --bind to open file descriptors (#1809)
Fixes #1107
2018-11-16 20:21:13 +03:00
Berker Peksag
c66957bbe9 Add support for named constants in the --ssl-version flag
Fixes #1114

Co-Authored-By: Brett Randall <javabrett@gmail.com>
Signed-off-by: Brett Randall <javabrett@gmail.com>
2018-10-31 14:43:40 +03:00
Konstantin vz'One Enchant
927fb2ba02 Prevent removal unix socket for reuse_port (#1887)
If you have two (or more) instances of gunicorn that use `reuse-port`
and bind to single unix socket all work until one of gunicorn will
stopped. Because the first stopped removes unix socket file and other
instances can't longer process requests.
2018-10-02 13:25:35 +02:00