
    >/iY                         S r SSKrSSKrSSKJr  SSKJr  SS jrS rS r	\R                  " S5      \R                  " S	5      S
 5       5       rg)a  
=================================
B202: Test for tarfile.extractall
=================================

This plugin will look for usage of ``tarfile.extractall()``

Severity are set as follows:

* ``tarfile.extractall(members=function(tarfile))`` - LOW
* ``tarfile.extractall(members=?)`` - member is not a function - MEDIUM
* ``tarfile.extractall()`` - members from the archive is trusted - HIGH

Use ``tarfile.extractall(members=function_name)`` and define a function
that will inspect each member. Discard files that contain a directory
traversal sequences such as ``../`` or ``\..`` along with all special filetypes
unless you explicitly need them.

:Example:

.. code-block:: none

    >> Issue: [B202:tarfile_unsafe_members] tarfile.extractall used without
    any validation. You should check members and discard dangerous ones
    Severity: High   Confidence: High
    CWE: CWE-22 (https://cwe.mitre.org/data/definitions/22.html)
    Location: examples/tarfile_extractall.py:8
    More Info:
    https://bandit.readthedocs.io/en/latest/plugins/b202_tarfile_unsafe_members.html
    7       tar = tarfile.open(filename)
    8       tar.extractall(path=tempfile.mkdtemp())
    9       tar.close()


.. seealso::

 - https://docs.python.org/3/library/tarfile.html#tarfile.TarFile.extractall
 - https://docs.python.org/3/library/tarfile.html#tarfile.TarInfo

.. versionadded:: 1.7.5

.. versionchanged:: 1.7.8
    Added check for filter parameter

    N)issue)test_propertiesc           	      H   U [         R                  :X  aX  [         R                  " [         R                  [         R                  [        R                  R
                  SR                  US9S9$ U [         R                  :X  aX  [         R                  " [         R                  [         R                  [        R                  R
                  SR                  US9S9$ [         R                  " [         R                  [         R                  [        R                  R
                  SS9$ )NzUsage of tarfile.extractall(members=function(tarfile)). Make sure your function properly discards dangerous members {members}).)members)severity
confidencecwetextzFound tarfile.extractall(members=?) but couldn't identify the type of members. Check if the members were properly validated {members}).z[tarfile.extractall used without any validation. Please check and discard dangerous members.)	banditLOWIssuer   CwePATH_TRAVERSALformatMEDIUMHIGH)levelr   s     _/home/james-whalen/.local/lib/python3.13/site-packages/bandit/plugins/tarfile_unsafe_members.py
exec_issuer   8   s    

||ZZzz		(( &&1
 	
 
&--	||]]}}		(( !&&1
 	
 ||[[{{		((:	
 	
    c                 N   U R                   R                   H  nUR                  S:X  d  M  UR                  n[	        U[
        R                  5      (       a  SUR                  R                  0s  $ [	        U[
        R                  5      (       a  UR                  OUnSU0s  $    g )Nr   FunctionOther)
nodekeywordsargvalue
isinstanceastCallfuncidName)contextkeywordr   r   s       r   get_members_valuer&   V   su    <<((;;)#--C#sxx(("CHHKK00",S#((";";'' )r   c                     U R                   R                   HQ  nUR                  S:X  d  M  UR                  n[	        U[
        R                  5      =(       a    UR                  S:H  s  $    g )Nfilterdata)r   r   r   r   r   r   Constant)r$   r%   r   s      r   is_filter_datar+   a   sJ    <<((;;("--Cc3<<0HSYY&5HH )r   B202r    c                 ~   [        U R                  S5      SU R                  ;   /5      (       a  SU R                  ;   a  [	        U 5      (       a  g SU R                  ;   aE  [        U 5      nSU;   a  [        [        R                  U5      $ [        [        R                  U5      $ [        [        R                  5      $ g )Ntarfile
extractallr(   r   r   )allis_module_imported_exactcall_function_namecall_keywordsr+   r&   r   r   r   r   r   )r$   r   s     r   tarfile_unsafe_membersr4   h   s     ,,Y7G666	
  w,,,1H1H---'0GW$!&**g66!&--99&++&&r   ) )__doc__r   r   bandit.corer   r   testr   r&   r+   test_idchecksr4    r   r   <module>r<      sW   ,Z    /
<(I fV'  'r   