§
    ê“?j¿-  ã                   ól  — d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ dZ ej        e¦  «        Zdd„Zdd„Zdd„Z	 d d„Z  G d„ de¦  «        Z! G d„ d¦  «        Z" G d„ de¦  «        Z#d„ Z$dS )!é    N)Úurlparse)Ú	Blueprint)Úcurrent_app)Úg)Úrequest)Úsession)ÚBadData)ÚSignatureExpired)ÚURLSafeTimedSerializer)Úescape)ÚMarkup)Ú
BadRequest)ÚValidationError)ÚCSRF)Úgenerate_csrfÚvalidate_csrfÚcsrf_meta_tagÚCSRFProtectc                 ó¢  — t          | dt          j        d¬¦  «        } t          |ddd¬¦  «        }|t          v�rt	          | d¬¦  «        }|t
          vr@t          j        t          j	        d	¦  «        ¦  «         
                    ¦   «         t
          |<   	 |                     t
          |         ¦  «        }np# t          $ rc t          j        t          j	        d	¦  «        ¦  «         
                    ¦   «         t
          |<   |                     t
          |         ¦  «        }Y nw xY wt          t          ||¦  «         t          j        |¦  «        S )
a  Generate a CSRF token. The token is cached for a request, so multiple
    calls to this function will generate the same token.

    During testing, it might be useful to access the signed token in
    ``g.csrf_token`` and the raw token in ``session['csrf_token']``.

    :param secret_key: Used to securely sign the token. Default is
        ``WTF_CSRF_SECRET_KEY`` or ``SECRET_KEY``.
    :param token_key: Key where token is stored in session for comparison.
        Default is ``WTF_CSRF_FIELD_NAME`` or ``'csrf_token'``.
    ÚWTF_CSRF_SECRET_KEYú%A secret key is required to use CSRF.©ÚmessageÚWTF_CSRF_FIELD_NAMEÚ
csrf_tokenú%A field name is required to use CSRF.úwtf-csrf-token©Úsalté@   )Ú_get_configr   Ú
secret_keyr   r   r   ÚhashlibÚsha1ÚosÚurandomÚ	hexdigestÚdumpsÚ	TypeErrorÚsetattrÚget)r"   Ú	token_keyÚ
field_nameÚsÚtokens        úU/var/www/stessy.org/copro_gestion/venv/lib/python3.11/site-packages/flask_wtf/csrf.pyr   r      s:  € õ ØØÝÔØ7ð	ñ ô €Jõ ØØØØ7ð	ñ ô €Jð �ÐÑÝ" :Ð4DÐEÑEÔEˆà�WÐ$Ð$Ý")¤,­r¬z¸"©~¬~Ñ">Ô">×"HÒ"HÑ"JÔ"J�G�JÑð	1Ø—G’G�G JÔ/Ñ0Ô0ˆEˆEøÝð 	1ð 	1ð 	1Ý")¤,­r¬z¸"©~¬~Ñ">Ô">×"HÒ"HÑ"JÔ"J�G�JÑØ—G’G�G JÔ/Ñ0Ô0ˆEˆEˆEð	1øøøõ 	•�:˜uÑ%Ô%Ð%åŒ5�ÑÔÐs   Â B7 Â7A*D$Ä#D$c                 ó  — t          |dt          j        d¬¦  «        }t          |ddd¬¦  «        }t          |ddd	¬
¦  «        }| st          d¦  «        ‚|t          vrt          d¦  «        ‚t          |d¬¦  «        }	 |                     | |¬¦  «        }n?# t          $ r}t          d¦  «        |‚d}~wt          $ r}t          d¦  «        |‚d}~ww xY wt          j
        t          |         |¦  «        st          d¦  «        ‚dS )a  Check if the given data is a valid CSRF token. This compares the given
    signed token to the one stored in the session.

    :param data: The signed CSRF token to be checked.
    :param secret_key: Used to securely sign the token. Default is
        ``WTF_CSRF_SECRET_KEY`` or ``SECRET_KEY``.
    :param time_limit: Number of seconds that the token is valid. Default is
        ``WTF_CSRF_TIME_LIMIT`` or 3600 seconds (60 minutes).
    :param token_key: Key where token is stored in session for comparison.
        Default is ``WTF_CSRF_FIELD_NAME`` or ``'csrf_token'``.

    :raises ValidationError: Contains the reason that validation failed.

    .. versionchanged:: 0.14
        Raises ``ValidationError`` with a specific error message rather than
        returning ``True`` or ``False``.
    r   r   r   r   r   r   ÚWTF_CSRF_TIME_LIMITé  F)ÚrequiredzThe CSRF token is missing.z"The CSRF session token is missing.r   r   )Úmax_agezThe CSRF token has expired.NzThe CSRF token is invalid.zThe CSRF tokens do not match.)r!   r   r"   r   r   r   Úloadsr
   r	   ÚhmacÚcompare_digest)Údatar"   Ú
time_limitr,   r-   r.   r/   Úes           r0   r   r   D   sV  € õ& ØØÝÔØ7ð	ñ ô €Jõ ØØØØ7ð	ñ ô €Jõ ˜ZÐ)>ÀÈuÐUÑUÔU€Jàð <ÝÐ:Ñ;Ô;Ð;à�Ð Ð ÝÐBÑCÔCÐCå˜zÐ0@ÐAÑAÔA€AðCØ—’˜ j�Ñ1Ô1ˆˆøÝð Dð Dð DÝÐ;Ñ<Ô<À!ÐCøøøøÝð Cð Cð CÝÐ:Ñ;Ô;ÀÐBøøøøðCøøøõ Ô�w zÔ2°EÑ:Ô:ð ?ÝÐ=Ñ>Ô>Ð>ð?ð ?s$   Á?B Â
CÂ!B1Â1CÂ>CÃCc                 ó¦   — t          | dd¦  «        } t          ||¬¦  «        }t          dt          | ¦  «        › dt          |¦  «        › d�¦  «        S )a?  Render an HTML ``<meta>`` tag carrying the CSRF token, following the
    convention used by Rails and recommended by OWASP for SPA and AJAX clients.

    Extract the token client-side with
    ``document.querySelector('meta[name="csrf-token"]').content`` and send it
    in the ``X-CSRFToken`` header of state-changing requests.

    :param name: Value of the meta tag's ``name`` attribute. Default is
        ``WTF_CSRF_META_NAME`` or ``'csrf-token'``.
    :param secret_key: Forwarded to :func:`generate_csrf`.
    :param token_key: Forwarded to :func:`generate_csrf`.
    ÚWTF_CSRF_META_NAMEú
csrf-token©r"   r,   z<meta name="z" content="z">)r!   r   r   r   )Únamer"   r,   r/   s       r0   r   r   x   sV   € õ �tÐ1°<Ñ@Ô@€DÝ Z¸9ÐEÑEÔE€EÝÐK¥¨¡¤ÐKÐK½&À¹-¼-ÐKÐKÐKÑLÔLÐLó    TúCSRF is not configured.c                 óp   — | € t           j                             ||¦  «        } |r| €t          |¦  «        ‚| S )a¦  Find config value based on provided value, Flask config, and default
    value.

    :param value: already provided config value
    :param config_name: Flask ``config`` key
    :param default: default value if not provided or configured
    :param required: whether the value must not be ``None``
    :param message: error message if required config is not found
    :raises KeyError: if required config is not found
    )r   Úconfigr+   ÚRuntimeError)ÚvalueÚconfig_nameÚdefaultr4   r   s        r0   r!   r!   ‹   s@   € ð €}ÝÔ"×&Ò& {°GÑ<Ô<ˆàð $�E�MÝ˜7Ñ#Ô#Ð#à€LrA   c                   ó*   ‡ — e Zd Zˆ fd„Zd„ Zd„ Zˆ xZS )Ú_FlaskFormCSRFc                 ó^   •— |j         | _         t          ¦   «                              |¦  «        S ©N)ÚmetaÚsuperÚ
setup_form)ÚselfÚformÚ	__class__s     €r0   rO   z_FlaskFormCSRF.setup_form£   s$   ø€ Ø”IˆŒ	Ý‰wŒw×!Ò! $Ñ'Ô'Ð'rA   c                 óL   — t          | j        j        | j        j        ¬¦  «        S )Nr?   )r   rM   Úcsrf_secretÚcsrf_field_name)rP   Úcsrf_token_fields     r0   Úgenerate_csrf_tokenz"_FlaskFormCSRF.generate_csrf_token§   s(   € ÝØ”yÔ,¸¼	Ô8Qð
ñ 
ô 
ð 	
rA   c                 ó  — t          j        dd¦  «        rd S 	 t          |j        | j        j        | j        j        | j        j        ¦  «         d S # t          $ r+}t           
                    |j        d         ¦  «         ‚ d }~ww xY w)NÚ
csrf_validFr   )r   r+   r   r9   rM   rT   Úcsrf_time_limitrU   r   ÚloggerÚinfoÚargs)rP   rQ   Úfieldr;   s       r0   Úvalidate_csrf_tokenz"_FlaskFormCSRF.validate_csrf_token¬   s•   € ÝŒ5�˜uÑ%Ô%ð 	àˆFð		ÝØ”
Ø”	Ô%Ø”	Ô)Ø”	Ô)ñ	ô ð ð ð øõ ð 	ð 	ð 	Ý�KŠK˜œ˜qœ	Ñ"Ô"Ð"Øøøøøð	øøøs   ™5A Á
BÁ&B Â B)Ú__name__Ú
__module__Ú__qualname__rO   rW   r_   Ú__classcell__)rR   s   @r0   rJ   rJ   ¢   sV   ø€ € € € € ð(ð (ð (ð (ð (ð
ð 
ð 
ð
ð ð ð ð ð ð rA   rJ   c                   ó@   — e Zd ZdZdd„Zd„ Zd„ Zdd„Zd„ Zd	„ Z	d
„ Z
dS )r   a[  Enable CSRF protection globally for a Flask app.

    ::

        app = Flask(__name__)
        csrf = CSRFProtect(app)

    Checks the ``csrf_token`` field sent with forms, or the ``X-CSRFToken``
    header sent with JavaScript requests. Render the token in templates using
    ``{{ csrf_token() }}``.

    See the :ref:`csrf` documentation.
    Nc                 ó„   — t          ¦   «         | _        t          ¦   «         | _        |r|                      |¦  «         d S d S rL   )ÚsetÚ_exempt_viewsÚ_exempt_blueprintsÚinit_app)rP   Úapps     r0   Ú__init__zCSRFProtect.__init__Ì   sD   € Ý ™UœUˆÔÝ"%¡%¤%ˆÔàð 	Ø�MŠM˜#ÑÔÐÐÐð	ð 	rA   c                 ó¢  ‡ ‡— ‰ ‰j         d<   ‰j                             dd¦  «         ‰j                             dd¦  «         t          ‰j                             dg d¢¦  «        ¦  «        ‰j        d<   ‰j                             dd¦  «         ‰j                             d	d
dg¦  «         ‰j                             dd¦  «         ‰j                             dd¦  «         ‰j                             dd¦  «         t
          ‰j        j        d<   t          ‰j        j        d<   ‰ 	                    d„ ¦  «         ‰j
        ˆˆ fd„¦   «         }d S )NÚcsrfÚWTF_CSRF_ENABLEDTÚWTF_CSRF_CHECK_DEFAULTÚWTF_CSRF_METHODS)ÚPOSTÚPUTÚPATCHÚDELETEr   r   ÚWTF_CSRF_HEADERSzX-CSRFTokenzX-CSRF-Tokenr=   r>   r2   r3   ÚWTF_CSRF_SSL_STRICTr   c                  ó    — t           t          dœS )N)r   r   )r   r   © rA   r0   ú<lambda>z&CSRFProtect.init_app.<locals>.<lambda>ä   s   € ¥=Å=ÐQÐQ€ rA   c                  óp   •— ‰ j         d         sd S ‰ j         d         sd S ‰                     d¬¦  «         d S )Nrn   ro   T)Úapply_exemptions)rD   Úprotect)rj   rP   s   €€r0   Úcsrf_protectz*CSRFProtect.init_app.<locals>.csrf_protectç   sG   ø€ à”:Ð0Ô1ð Ø�à”:Ð6Ô7ð Ø�à�LŠL¨$ˆLÑ/Ô/Ð/Ð/Ð/rA   )Ú
extensionsrD   Ú
setdefaultrf   r+   r   Ú	jinja_envÚglobalsr   Úcontext_processorÚbefore_request)rP   rj   r}   s   `` r0   ri   zCSRFProtect.init_appÓ   sl  øø€ Ø!%ˆŒ�vÑàŒ
×ÒÐ0°$Ñ7Ô7Ð7ØŒ
×ÒÐ6¸Ñ=Ô=Ð=Ý),ØŒJ�NŠNÐ-Ð/QÐ/QÐ/QÑRÔRñ*
ô *
ˆŒ
Ð%Ñ&ð 	Œ
×ÒÐ3°\ÑBÔBÐBØŒ
×ÒÐ0°=À.Ð2QÑRÔRÐRØŒ
×ÒÐ2°LÑAÔAÐAØŒ
×ÒÐ3°TÑ:Ô:Ð:ØŒ
×ÒÐ3°TÑ:Ô:Ð:å.;ˆŒÔ˜lÑ+Ý1>ˆŒÔ˜oÑ.Ø×ÒØQÐQñ	
ô 	
ð 	
ð 
Ô	ð	0ð 	0ð 	0ð 	0ð 	0ñ 
Ô	ð	0ð 	0ð 	0rA   c                 ó\  — t           j        d         }t          j                             |¦  «        }|r|S t          j        D ]/}|                     |¦  «        rt          j        |         }|r|c S Œ0t           j        d         D ]'}t          j                             |¦  «        }|r|c S Œ(d S )Nr   ru   )r   rD   r   rQ   r+   ÚendswithÚheaders)rP   r-   Ú
base_tokenÚkeyr   Úheader_names         r0   Ú_get_csrf_tokenzCSRFProtect._get_csrf_tokenñ   sÊ   € å Ô'Ð(=Ô>ˆ
Ý”\×%Ò% jÑ1Ô1ˆ
àð 	ØÐõ ”<ð 	&ð 	&ˆCØ�|Š|˜JÑ'Ô'ð &Ý$œ\¨#Ô.�
àð &Ø%Ð%Ð%Ð%øõ 'Ô-Ð.@ÔAð 	"ð 	"ˆKÝ œ×,Ò,¨[Ñ9Ô9ˆJàð "Ø!Ð!Ð!Ð!ð"ð ˆtrA   Fc                 ó¤  — |r$t           j        sdS |                      ¦   «         rdS t           j        t          j        d         vrdS 	 t          |                      ¦   «         ¦  «         n\# t          $ rO}t           
                    |j        d         ¦  «         |                      |j        d         ¦  «         Y d}~nd}~ww xY wt           j        rrt          j        d         r`t           j        s|                      d¦  «         dt           j        › d�}t!          t           j        |¦  «        s|                      d¦  «         d	t"          _        dS )
a0  Validate CSRF on the current request.

        When ``apply_exemptions`` is ``True``, views and blueprints marked with
        :meth:`exempt` are skipped. This lets you combine a custom
        ``before_request`` hook (or any manual call) with the declarative
        ``@csrf.exempt`` decorator.
        Nrp   r   rv   zThe referrer header is missing.zhttps://ú/z%The referrer does not match the host.T)r   ÚendpointÚ
_is_exemptÚmethodr   rD   r   rŠ   r   r[   r\   r]   Ú_error_responseÚ	is_secureÚreferrerÚhostÚsame_originr   rY   )rP   r{   r;   Úgood_referrers       r0   r|   zCSRFProtect.protect
  sX  € ð ð 	ÝÔ#ð Ø�à�ŠÑ Ô ð Ø�åŒ>¥Ô!3Ð4FÔ!GÐGÐGØˆFð	,Ý˜$×.Ò.Ñ0Ô0Ñ1Ô1Ð1Ð1øÝð 	,ð 	,ð 	,Ý�KŠK˜œ˜qœ	Ñ"Ô"Ð"Ø× Ò  ¤¨¤Ñ+Ô+Ð+Ð+Ð+Ð+Ð+Ð+øøøøð	,øøøõ Ôð 	N¥Ô!3Ð4IÔ!Jð 	NÝÔ#ð HØ×$Ò$Ð%FÑGÔGÐGà6¥w¤|Ð6Ð6Ð6ˆMå�wÔ/°Ñ?Ô?ð NØ×$Ò$Ð%LÑMÔMÐMà�Œˆˆs   Á!A* Á*
CÁ4AB>Â>Cc                 óô   — t           j                             t          j        ¦  «        | j        v rdS t           j                             t          j        ¦  «        }|€dS |j        › d|j	        › �}|| j
        v S )NTFú.)r   Ú
blueprintsr+   r   Ú	blueprintrh   Úview_functionsr�   ra   r`   rg   )rP   ÚviewÚdests      r0   rŽ   zCSRFProtect._is_exempt.  sq   € ÝÔ!×%Ò%¥gÔ&7Ñ8Ô8¸DÔ<SÐSÐSØ�4åÔ)×-Ò-­gÔ.>Ñ?Ô?ˆØˆ<Ø�5à”/Ð3Ð3 D¤MÐ3Ð3ˆØ�tÔ)Ð)Ð)rA   c                 ó  — t          |t          ¦  «        r| j                             |¦  «         |S t          |t          ¦  «        r|}n!d                     |j        |j        f¦  «        }| j                             |¦  «         |S )a  Mark a view or blueprint to be excluded from CSRF protection.

        ::

            @app.route('/some-view', methods=['POST'])
            @csrf.exempt
            def some_view():
                ...

        ::

            bp = Blueprint(...)
            csrf.exempt(bp)

        r—   )	Ú
isinstancer   rh   ÚaddÚstrÚjoinra   r`   rg   )rP   r›   Úview_locations      r0   ÚexemptzCSRFProtect.exempt9  s‚   € õ" �d�IÑ&Ô&ð 	ØÔ#×'Ò'¨Ñ-Ô-Ð-ØˆKå�d�CÑ Ô ð 	GØ ˆMˆMàŸHšH d¤o°t´}Ð%EÑFÔFˆMàÔ×Ò˜}Ñ-Ô-Ð-ØˆrA   c                 ó    — t          |¦  «        ‚rL   )Ú	CSRFError)rP   Úreasons     r0   r�   zCSRFProtect._error_responseV  s   € Ý˜ÑÔÐrA   rL   )F)r`   ra   rb   Ú__doc__rk   ri   rŠ   r|   rŽ   r£   r�   rx   rA   r0   r   r   ½   s’   € € € € € ðð ðð ð ð ð0ð 0ð 0ð<ð ð ð2"ð "ð "ð "ðH	*ð 	*ð 	*ðð ð ð: ð  ð  ð  ð  rA   r   c                   ó   — e Zd ZdZdZdS )r¥   zïRaise if the client sends invalid CSRF data with the request.

    Generates a 400 Bad Request response with the failure reason by default.
    Customize the response by registering a handler with
    :meth:`flask.Flask.errorhandler`.
    zCSRF validation failed.N)r`   ra   rb   r§   Údescriptionrx   rA   r0   r¥   r¥   Z  s   € € € € € ðð ð ,€K€K€KrA   r¥   c                 óž   — t          | ¦  «        }t          |¦  «        }|j        |j        k    o|j        |j        k    o|j        |j        k    S rL   )r   ÚschemeÚhostnameÚport)Úcurrent_uriÚcompare_uriÚcurrentÚcompares       r0   r”   r”   e  sS   € Ý�{Ñ#Ô#€GÝ�{Ñ#Ô#€Gð 	Œ˜'œ.Ò(ð 	)ØÔ Ô 0Ò0ð	)àŒL˜GœLÒ(ðrA   )NN)NNN)NTrB   )%r#   r7   Úloggingr%   Úurllib.parser   Úflaskr   r   r   r   r   Úitsdangerousr	   r
   r   Ú
markupsafer   r   Úwerkzeug.exceptionsr   Úwtformsr   Úwtforms.csrf.corer   Ú__all__Ú	getLoggerr`   r[   r   r   r   r!   rJ   r   r¥   r”   rx   rA   r0   ú<module>r¼      s6  ðØ €€€Ø €€€Ø €€€Ø 	€	€	€	Ø !Ð !Ð !Ð !Ð !Ð !à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø  Ð  Ð  Ð  Ð  Ð  Ø )Ð )Ð )Ð )Ð )Ð )Ø /Ð /Ð /Ð /Ð /Ð /Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø *Ð *Ð *Ð *Ð *Ð *Ø #Ð #Ð #Ð #Ð #Ð #Ø "Ð "Ð "Ð "Ð "Ð "à
L€Ø	ˆÔ	˜8Ñ	$Ô	$€ð(ð (ð (ð (ðV1?ð 1?ð 1?ð 1?ðhMð Mð Mð Mð( >Wðð ð ð ð.ð ð ð ð �Tñ ô ð ð6Z ð Z ð Z ð Z ð Z ñ Z ô Z ð Z ðz,ð ,ð ,ð ,ð ,�
ñ ,ô ,ð ,ðð ð ð ð rA   