|
Server : Apache System : Linux cvar2.toservers.com 3.10.0-962.3.2.lve1.5.73.el7.x86_64 #1 SMP Wed Aug 24 21:31:23 UTC 2022 x86_64 User : njnconst ( 1116) PHP Version : 8.4.18 Disable Function : NONE Directory : /usr/lib/python2.7/site-packages/werkzeug/middleware/ |
Upload File : |
�
./�_c @ s0 d Z d d l m Z d e f d � � YZ d S( s>
X-Forwarded-For Proxy Fix
=========================
This module provides a middleware that adjusts the WSGI environ based on
``X-Forwarded-`` headers that proxies in front of an application may
set.
When an application is running behind a proxy server, WSGI may see the
request as coming from that server rather than the real client. Proxies
set various headers to track where the request actually came from.
This middleware should only be applied if the application is actually
behind such a proxy, and should be configured with the number of proxies
that are chained in front of it. Not all proxies set all the headers.
Since incoming headers can be faked, you must set how many proxies are
setting each header so the middleware knows what to trust.
.. autoclass:: ProxyFix
:copyright: 2007 Pallets
:license: BSD-3-Clause
i����( t parse_list_headert ProxyFixc B s8 e Z d Z d d d d d d � Z d � Z d � Z RS( s$ Adjust the WSGI environ based on ``X-Forwarded-`` that proxies in
front of the application may set.
- ``X-Forwarded-For`` sets ``REMOTE_ADDR``.
- ``X-Forwarded-Proto`` sets ``wsgi.url_scheme``.
- ``X-Forwarded-Host`` sets ``HTTP_HOST``, ``SERVER_NAME``, and
``SERVER_PORT``.
- ``X-Forwarded-Port`` sets ``HTTP_HOST`` and ``SERVER_PORT``.
- ``X-Forwarded-Prefix`` sets ``SCRIPT_NAME``.
You must tell the middleware how many proxies set each header so it
knows what values to trust. It is a security issue to trust values
that came from the client rather than a proxy.
The original values of the headers are stored in the WSGI
environ as ``werkzeug.proxy_fix.orig``, a dict.
:param app: The WSGI application to wrap.
:param x_for: Number of values to trust for ``X-Forwarded-For``.
:param x_proto: Number of values to trust for ``X-Forwarded-Proto``.
:param x_host: Number of values to trust for ``X-Forwarded-Host``.
:param x_port: Number of values to trust for ``X-Forwarded-Port``.
:param x_prefix: Number of values to trust for
``X-Forwarded-Prefix``.
.. code-block:: python
from werkzeug.middleware.proxy_fix import ProxyFix
# App is behind one proxy that sets the -For and -Host headers.
app = ProxyFix(app, x_for=1, x_host=1)
.. versionchanged:: 1.0
Deprecated code has been removed:
* The ``num_proxies`` argument and attribute.
* The ``get_remote_addr`` method.
* The environ keys ``orig_remote_addr``,
``orig_wsgi_url_scheme``, and ``orig_http_host``.
.. versionchanged:: 0.15
All headers support multiple values. The ``num_proxies``
argument is deprecated. Each header is configured with a
separate number of trusted proxies.
.. versionchanged:: 0.15
Original WSGI environ values are stored in the
``werkzeug.proxy_fix.orig`` dict. ``orig_remote_addr``,
``orig_wsgi_url_scheme``, and ``orig_http_host`` are deprecated
and will be removed in 1.0.
.. versionchanged:: 0.15
Support ``X-Forwarded-Port`` and ``X-Forwarded-Prefix``.
.. versionchanged:: 0.15
``X-Forwarded-Host`` and ``X-Forwarded-Port`` modify
``SERVER_NAME`` and ``SERVER_PORT``.
i i c C s: | | _ | | _ | | _ | | _ | | _ | | _ d S( N( t appt x_fort x_protot x_hostt x_portt x_prefix( t selfR R R R R R ( ( sA /tmp/pip-install-sTXtzD/Werkzeug/werkzeug/middleware/proxy_fix.pyt __init__V s c C s; | o | s d St | � } t | � | k r7 | | Sd S( s� Get the real value from a list header based on the configured
number of trusted proxies.
:param trusted: Number of values to trust in the header.
:param value: Comma separated list header value to parse.
:return: The real value, or ``None`` if there are fewer values
than the number of trusted proxies.
.. versionchanged:: 1.0
Renamed from ``_get_trusted_comma``.
.. versionadded:: 0.15
N( R t len( R t trustedt valuet values( ( sA /tmp/pip-install-sTXtzD/Werkzeug/werkzeug/middleware/proxy_fix.pyt _get_real_value^ s
c C s | j } | d � } | d � } | d � } | j i i | d 6| d 6| d 6| d � d 6| d � d 6| d � d 6d 6� | j | j | d � � } | r� | | d <n | j | j | d � � } | r� | | d <n | j | j | d
� � } | rJ| | d <| j d d � }
|
d
| d <t |
� d k rJ|
d | d <qJn | j | j | d � � } | r�| j d � } | r�| j d d � }
t |
� d k r�|
d
n | } d | | f | d <n | | d <n | j | j | d � � }
|
r|
| d <n | j
| | � S( s� Modify the WSGI environ based on the various ``Forwarded``
headers before calling the wrapped application. Store the
original environ values in ``werkzeug.proxy_fix.orig_{key}``.
t REMOTE_ADDRs wsgi.url_schemet HTTP_HOSTt SERVER_NAMEt SERVER_PORTt SCRIPT_NAMEs werkzeug.proxy_fix.origt HTTP_X_FORWARDED_FORt HTTP_X_FORWARDED_PROTOt HTTP_X_FORWARDED_HOSTt :i i i t HTTP_X_FORWARDED_PORTs %s:%st HTTP_X_FORWARDED_PREFIX( t gett updateR R R R t splitR
R R R ( R t environt start_responset environ_gett orig_remote_addrt orig_wsgi_url_schemet orig_http_hostR R R t partsR t hostR ( ( sA /tmp/pip-install-sTXtzD/Werkzeug/werkzeug/middleware/proxy_fix.pyt __call__r sP
"
( t __name__t
__module__t __doc__R R R% ( ( ( sA /tmp/pip-install-sTXtzD/Werkzeug/werkzeug/middleware/proxy_fix.pyR s 9 N( R( t
werkzeug.httpR t objectR ( ( ( sA /tmp/pip-install-sTXtzD/Werkzeug/werkzeug/middleware/proxy_fix.pyt <module> s