Skip to content

Commit 687b78d

Browse files
committed
config defaults: PATH_NAME and ::1 for proxy
* PATH_NAME is used like SCRIPT_NAME: include both * replicate changed forwarded-allow-ips default to proxy_allow_ips
1 parent 5bbf373 commit 687b78d

File tree

3 files changed

+64
-38
lines changed

3 files changed

+64
-38
lines changed

docs/source/news.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ Changelog
1313
- sdist generation now explicitly excludes sphinx build folder (:pr:`3257`)
1414
- decode bytes-typed status (as can be passed by gevent) as utf-8 instead of raising `TypeError` (:pr:`2336`)
1515
- raise correct Exception when encounting invalid chunked requests (:pr:`3258`)
16-
- the SCRIPT_NAME header when received from allowed forwarders is no longer restricted for containing an underscore (:pr:`3192`)
16+
- the SCRIPT_NAME and PATH_INFO headers, when received from allowed forwarders, are no longer restricted for containing an underscore (:pr:`3192`)
17+
- include IPv6 loopback address ``[::1]`` in default for :ref:`forwarded-allow-ips` and :ref:`proxy-allow-ips` (:pr:`3192`)
1718

1819
** NOTE **
1920

2021
- The SCRIPT_NAME change mitigates a regression that appeared first in the 22.0.0 release
21-
- Review your ``forwarded-allow-ips`` setting if you are still not seeing the SCRIPT_NAME transmitted
22+
- Review your :ref:`forwarded-allow-ips` setting if you are still not seeing the SCRIPT_NAME transmitted
23+
- Review your :ref:`forwarder-headers` setting if you are missing headers after upgrading from a version prior to 22.0.0
2224

2325
** Breaking changes **
2426

2527
- refuse requests where the uri field is empty (:pr:`3255`)
2628
- refuse requests with invalid CR/LR/NUL in heade field values (:pr:`3253`)
27-
- remove temporary `--tolerate-dangerous-framing` switch from 22.0 (:pr:`3260`)
29+
- remove temporary ``--tolerate-dangerous-framing`` switch from 22.0 (:pr:`3260`)
2830
- If any of the breaking changes affect you, be aware that now refused requests can post a security problem, especially so in setups involving request pipe-lining and/or proxies.
2931

3032
22.0.0 - 2024-04-17

docs/source/settings.rst

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ temporary directory.
12081208

12091209
A dictionary containing headers and values that the front-end proxy
12101210
uses to indicate HTTPS requests. If the source IP is permitted by
1211-
``forwarded-allow-ips`` (below), *and* at least one request header matches
1211+
:ref:`forwarded-allow-ips` (below), *and* at least one request header matches
12121212
a key-value pair listed in this dictionary, then Gunicorn will set
12131213
``wsgi.url_scheme`` to ``https``, so your application can tell that the
12141214
request is secure.
@@ -1235,16 +1235,21 @@ the headers defined here can not be passed directly from the client.
12351235
**Default:** ``'127.0.0.1,::1'``
12361236

12371237
Front-end's IPs from which allowed to handle set secure headers.
1238-
(comma separate).
1238+
(comma separated).
12391239

1240-
Set to ``*`` to disable checking of Front-end IPs. This is useful for setups
1241-
where you don't know in advance the IP address of Front-end, but
1242-
instead have ensured via other means that none other than your
1243-
authorized Front-ends can access gunicorn.
1240+
Set to ``*`` to disable checking of front-end IPs. This is useful for setups
1241+
where you don't know in advance the IP address of front-end, but
1242+
instead have ensured via other means that only your
1243+
authorized front-ends can access Gunicorn.
12441244

12451245
By default, the value of the ``FORWARDED_ALLOW_IPS`` environment
12461246
variable. If it is not defined, the default is ``"127.0.0.1,::1"``.
12471247

1248+
.. note::
1249+
1250+
This option does not affect UNIX socket connections. Connections not associated with
1251+
an IP address are treated as allowed, unconditionally.
1252+
12481253
.. note::
12491254

12501255
The interplay between the request headers, the value of ``forwarded_allow_ips``, and the value of
@@ -1370,13 +1375,19 @@ Example for stunnel config::
13701375

13711376
**Command line:** ``--proxy-allow-from``
13721377

1373-
**Default:** ``'127.0.0.1'``
1378+
**Default:** ``'127.0.0.1,::1'``
13741379

1375-
Front-end's IPs from which allowed accept proxy requests (comma separate).
1380+
Front-end's IPs from which allowed accept proxy requests (comma separated).
1381+
1382+
Set to ``*`` to disable checking of front-end IPs. This is useful for setups
1383+
where you don't know in advance the IP address of front-end, but
1384+
instead have ensured via other means that only your
1385+
authorized front-ends can access Gunicorn.
1386+
1387+
.. note::
13761388

1377-
Set to ``*`` to disable checking of Front-end IPs (useful for setups
1378-
where you don't know in advance the IP address of Front-end, but
1379-
you still trust the environment)
1389+
This option does not affect UNIX socket connections. Connections not associated with
1390+
an IP address are treated as allowed, unconditionally.
13801391

13811392
.. _raw-paste-global-conf:
13821393

@@ -1486,14 +1497,15 @@ Use with care and only if necessary. Deprecated; scheduled for removal in 24.0.0
14861497

14871498
**Command line:** ``--forwarder-headers``
14881499

1489-
**Default:** ``'SCRIPT_NAME'``
1500+
**Default:** ``'SCRIPT_NAME,PATH_INFO'``
14901501

14911502
A list containing upper-case header field names that the front-end proxy
1492-
sets, to be used in WSGI environment.
1503+
(see :ref:`forwarded-allow-ips`) sets, to be used in WSGI environment.
14931504

1494-
If headers named in this list are not present in the request, they will be ignored.
1505+
This option has no effect for headers not present in the request.
14951506

1496-
This option can be used to transfer SCRIPT_NAME and REMOTE_USER.
1507+
This option can be used to transfer ``SCRIPT_NAME``, ``PATH_INFO``
1508+
and ``REMOTE_USER``.
14971509

14981510
It is important that your front-end proxy configuration ensures that
14991511
the headers defined here can not be passed directly from the client.
@@ -1518,8 +1530,8 @@ The value ``refuse`` will return an error if a request contains *any* such heade
15181530
The value ``dangerous`` matches the previous, not advisable, behaviour of mapping different
15191531
header field names into the same environ name.
15201532

1521-
If the source IP is permitted by ``forwarded-allow-ips``, *and* the header name is
1522-
present in ``forwarder-headers``, the header is mapped into environment regardless of
1533+
If the source is permitted as explained in :ref:`forwarded-allow-ips`, *and* the header name is
1534+
present in :ref:`forwarder-headers`, the header is mapped into environment regardless of
15231535
the state of this setting.
15241536

15251537
Use with care and only if necessary and after considering if your problem could

gunicorn/config.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ class SecureSchemeHeader(Setting):
12501250
12511251
A dictionary containing headers and values that the front-end proxy
12521252
uses to indicate HTTPS requests. If the source IP is permitted by
1253-
``forwarded-allow-ips`` (below), *and* at least one request header matches
1253+
:ref:`forwarded-allow-ips` (below), *and* at least one request header matches
12541254
a key-value pair listed in this dictionary, then Gunicorn will set
12551255
``wsgi.url_scheme`` to ``https``, so your application can tell that the
12561256
request is secure.
@@ -1278,16 +1278,21 @@ class ForwardedAllowIPS(Setting):
12781278
default = os.environ.get("FORWARDED_ALLOW_IPS", "127.0.0.1,::1")
12791279
desc = """\
12801280
Front-end's IPs from which allowed to handle set secure headers.
1281-
(comma separate).
1281+
(comma separated).
12821282
1283-
Set to ``*`` to disable checking of Front-end IPs. This is useful for setups
1284-
where you don't know in advance the IP address of Front-end, but
1285-
instead have ensured via other means that none other than your
1286-
authorized Front-ends can access gunicorn.
1283+
Set to ``*`` to disable checking of front-end IPs. This is useful for setups
1284+
where you don't know in advance the IP address of front-end, but
1285+
instead have ensured via other means that only your
1286+
authorized front-ends can access Gunicorn.
12871287
12881288
By default, the value of the ``FORWARDED_ALLOW_IPS`` environment
12891289
variable. If it is not defined, the default is ``"127.0.0.1,::1"``.
12901290
1291+
.. note::
1292+
1293+
This option does not affect UNIX socket connections. Connections not associated with
1294+
an IP address are treated as allowed, unconditionally.
1295+
12911296
.. note::
12921297
12931298
The interplay between the request headers, the value of ``forwarded_allow_ips``, and the value of
@@ -2075,14 +2080,20 @@ class ProxyAllowFrom(Setting):
20752080
name = "proxy_allow_ips"
20762081
section = "Server Mechanics"
20772082
cli = ["--proxy-allow-from"]
2078-
validator = validate_string_to_list
2079-
default = "127.0.0.1"
2083+
validator = validate_string_to_addr_list
2084+
default = "127.0.0.1,::1"
20802085
desc = """\
2081-
Front-end's IPs from which allowed accept proxy requests (comma separate).
2086+
Front-end's IPs from which allowed accept proxy requests (comma separated).
2087+
2088+
Set to ``*`` to disable checking of front-end IPs. This is useful for setups
2089+
where you don't know in advance the IP address of front-end, but
2090+
instead have ensured via other means that only your
2091+
authorized front-ends can access Gunicorn.
2092+
2093+
.. note::
20822094
2083-
Set to ``*`` to disable checking of Front-end IPs (useful for setups
2084-
where you don't know in advance the IP address of Front-end, but
2085-
you still trust the environment)
2095+
This option does not affect UNIX socket connections. Connections not associated with
2096+
an IP address are treated as allowed, unconditionally.
20862097
"""
20872098

20882099

@@ -2365,15 +2376,16 @@ class ForwarderHeaders(Setting):
23652376
section = "Server Mechanics"
23662377
cli = ["--forwarder-headers"]
23672378
validator = validate_string_to_list
2368-
default = "SCRIPT_NAME"
2379+
default = "SCRIPT_NAME,PATH_INFO"
23692380
desc = """\
23702381
23712382
A list containing upper-case header field names that the front-end proxy
2372-
sets, to be used in WSGI environment.
2383+
(see :ref:`forwarded-allow-ips`) sets, to be used in WSGI environment.
23732384
2374-
If headers named in this list are not present in the request, they will be ignored.
2385+
This option has no effect for headers not present in the request.
23752386
2376-
This option can be used to transfer SCRIPT_NAME and REMOTE_USER.
2387+
This option can be used to transfer ``SCRIPT_NAME``, ``PATH_INFO``
2388+
and ``REMOTE_USER``.
23772389
23782390
It is important that your front-end proxy configuration ensures that
23792391
the headers defined here can not be passed directly from the client.
@@ -2398,8 +2410,8 @@ class HeaderMap(Setting):
23982410
The value ``dangerous`` matches the previous, not advisable, behaviour of mapping different
23992411
header field names into the same environ name.
24002412
2401-
If the source IP is permitted by ``forwarded-allow-ips``, *and* the header name is
2402-
present in ``forwarder-headers``, the header is mapped into environment regardless of
2413+
If the source is permitted as explained in :ref:`forwarded-allow-ips`, *and* the header name is
2414+
present in :ref:`forwarder-headers`, the header is mapped into environment regardless of
24032415
the state of this setting.
24042416
24052417
Use with care and only if necessary and after considering if your problem could

0 commit comments

Comments
 (0)