"EۨmVUdZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z ddl mZd d lmZd d lmZd d lmZd d lmZejdejdejfZdZeZejeed<eZ ejeed<ddhZ!ddhZ"ddhZ#ej$e%gdfej&e%gdfej'e%gdfe e%gdffZ(ej)ej)ej*ej+efdfed<dejd ej,efd!Z-d"e.d e/fd#Z0d$ed efd%Z1d&ejd'ed e2fd(Z3d&ejd'ed e2fd)Z4Gd*d+eZ5Gd,d-e5Z6Gd.d/e Z7Gd0d1e7e Z8dS)2zA sandbox layer that ensures unsafe operations cannot be performed. Useful when the template itself comes from an untrusted source. N)formatter_field_name_split)abc)deque) Formatter)EscapeFormatter)Markup) Environment) SecurityError)Context) UndefinedF.)boundiUNSAFE_FUNCTION_ATTRIBUTESUNSAFE_METHOD_ATTRIBUTESgi_framegi_codecr_framecr_codeag_codeag_frame)addcleardifference_updatediscardpopremovesymmetric_difference_updateupdate)rrpopitem setdefaultr)appendreverseinsertsortextendr) r" appendleftrr& extendleftrpopleftrrotate _mutable_speccallablereturnct|tjtjfr |jdvrdS|j}t|t r|SdS)N)format format_map) isinstancetypes MethodTypeBuiltinMethodType__name____self__str)r,objs /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/jinja2/sandbox.pyinspect_format_methodr:Ss\ 5#U%<=    ": : :t  C#s 4argscxt|}t|tkrtdtd|S)zWA range that can't generate ranges with a length of more than MAX_RANGE items. z@Range too big. The sandbox blocks ranges larger than MAX_RANGE (z).)rangelen MAX_RANGE OverflowError)r<rngs r9 safe_rangerCasN ,C 3xx) )$ ) ) )   Jr;fcd|_|S)zMarks a function or method as unsafe. .. code-block: python @unsafe def delete(self): pass T)unsafe_callable)rDs r9unsaferGpsA Hr;r8attrct|tjr |tvrdSnt|tjr|tvs |t vrdSnt|t r |dkrdSnt|tjtjtj frdSt|tj r |tvrdSnuttdr&t|tj r |tvrdSn:ttdr%t|tjr |t vrdS|dS)aTest if the attribute given is an internal python attribute. For example this function returns `True` for the `func_code` attribute of python objects. This is useful if the environment method :meth:`~SandboxedEnvironment.is_safe_attribute` is overridden. >>> from jinja2.sandbox import is_internal_attribute >>> is_internal_attribute(str, "mro") True >>> is_internal_attribute(str, "upper") False Tmro CoroutineTypeAsyncGeneratorType__)r1r2 FunctionTyperr3rtypeCodeType TracebackType FrameType GeneratorTypeUNSAFE_GENERATOR_ATTRIBUTEShasattrrKUNSAFE_COROUTINE_ATTRIBUTESrL!UNSAFE_ASYNC_GENERATOR_ATTRIBUTES startswith)r8rHs r9is_internal_attributerY}sh#u)** - - -4 . C) * * - - -9Q1Q1Q42R C   5==4  C%.%*=uO P P t C, - -  . . .4 /  ( (ZU=P-Q-Q . . .4 / , - -* U %33 4 4 44 ??4  r;cLtD]\}}t||r||vcSdS)aThis function checks if an attribute on a builtin mutable object (list, dict, set or deque) or the corresponding ABCs would modify it if called. >>> modifies_known_mutable({}, "clear") True >>> modifies_known_mutable({}, "keys") False >>> modifies_known_mutable([], "append") True >>> modifies_known_mutable([], "index") False If called with an unsupported object, ``False`` is returned. >>> modifies_known_mutable("foo", "upper") False F)r+r1)r8rHtypespecrGs r9modifies_known_mutabler\sD&*""& c8 $ $ "6> ! ! ! " 5r;c eZdZUdZdZejejejej ej ej ej dZ ejeejejejgejffed<ejejdZejeejejgejffed<eZejeed<eZejeed<d ejd ejd d ffd Zdejdedejd efdZdejd efdZdededejdejd ejf dZ dededejd ejfdZ!dejdej"eejfd ej"eje#ffdZ$dejded ej"eje#ffdZ%dejded e#fdZ& d&ded ej'ejd fd ejeejfd!ej(ejd ef d"Z)d#ed$ejd ejd ejd ejf d%Z*xZ+S)'SandboxedEnvironmentaThe sandboxed environment. It works like the regular environment but tells the compiler to generate sandboxed code. Additionally subclasses of this environment may override the methods that tell the runtime what attributes or functions are safe to access. If the template tries to access insecure code a :exc:`SecurityError` is raised. However also other exceptions may occur during the rendering so the caller has to ensure that all exceptions are caught. T)+-*/z//z**%default_binop_table)r_r`default_unop_tableintercepted_binopsintercepted_unopsr<kwargsr-Nctj|i|t|jd<|j|_|j|_dS)Nr>) super__init__rCglobalsrdcopy binop_tablere unop_table)selfr<rh __class__s r9rkzSandboxedEnvironment.__init__s\$)&))) * W388::16688r;r8rHvaluecN|dpt|| S)aYThe sandboxed environment will call this method to check if the attribute of an object is safe to access. Per default all attributes starting with an underscore are considered private as well as the special attributes of internal python objects as returned by the :func:`is_internal_attribute` function. _)rXrY)rpr8rHrrs r9is_safe_attributez&SandboxedEnvironment.is_safe_attributes)OOC((L,A#t,L,LMMr;cHt|ddpt|dd S)zCheck if an object is safely callable. By default callables are considered safe unless decorated with :func:`unsafe`. This also recognizes the Django convention of setting ``func.alters_data = True``. rFF alters_data)getattr)rpr8s r9is_safe_callablez%SandboxedEnvironment.is_safe_callable s0 C*E 2 2 Xgc=RW6X6X  r;contextoperatorleftrightc0|j|||S)zFor intercepted binary operator calls (:meth:`intercepted_binops`) this function is executed instead of the builtin operator. This can be used to fine tune the behavior of certain operators. .. versionadded:: 2.6 )rn)rprzr{r|r}s r9 call_binopzSandboxedEnvironment.call_binops*t)$666r;argc.|j||S)zFor intercepted unary operator calls (:meth:`intercepted_unops`) this function is executed instead of the builtin operator. This can be used to fine tune the behavior of certain operators. .. versionadded:: 2.6 )ro)rprzr{rs r9 call_unopzSandboxedEnvironment.call_unop!s)tx(---r;argumentc ||S#ttf$rt|trt t|} t ||}||||r|cYS|||cYS#t$rYnwxYw#t$rYnwxYwYnwxYw| ||S)z(Subscribe an object from sandboxed code.r8name) TypeError LookupErrorr1r7rxruunsafe_undefinedAttributeError Exception undefined)rpr8rrHrrs r9getitemzSandboxedEnvironment.getitem*s Dx= ;' D D D(C(( D Dx==DD 'T 2 2 11#xGG)#(LLL#44S(CCCCC * !D  D~~#H~555sV &B'BBB',B' BB'BB' B!B' B!!B'&B' attributec t||}||||r|S|||S#t$r% ||cYS#tt f$rYnwxYwYnwxYw|||S)zSubscribe an object from sandboxed code and prefer the attribute. The attribute passed *must* be a bytestring. r)rxrurrrrr)rpr8rrrs r9rxzSandboxedEnvironment.getattrAs 9C++E%%c9e<<  ((i88 8    9~%%%{+      ~~#I~666s5A A0 AA0A*'A0)A**A0/A0cp|d|dt|jd||tS)z1Return an undefined object for unsafe attributes.zaccess to attribute z of z object is unsafe.)rr8exc)rrOr5r )rpr8rs r9rz%SandboxedEnvironment.unsafe_undefinedRsR~~ 99 9 9S " 9 9 9    r;s. format_funccxt|trt||j}nt |}|O|jdkrDt |dks|r%tdt ||duzd|d}d}||||}t||S) zIf a format call is detected, then this is routed through this method so that our safety sandbox can be used for it. )escapeNr0r z(format_map() takes exactly one argument z givenr) r1rSandboxedEscapeFormatterrSandboxedFormatterr5r?rvformatrO)rprr<rhr formatterrvs r9 format_stringz"SandboxedEnvironment.format_string\s a  10ahGGGII*400I  "{';|'K'K4yyA~~~AD V4%78AAA !WFD   q$ / /tAwwr{{r;_SandboxedEnvironment__context_SandboxedEnvironment__objct|}||||||S||st|d|j|g|Ri|S)z#Call an object from sandboxed code.Nz is not safely callable)r:rryr call)_SandboxedEnvironment__selfrrr<rhfmts r9rzSandboxedEnvironment.callys$E** ?''T65AA A&&u-- E5 C C CDD Dy~e5d555f555r;N),r5 __module__ __qualname____doc__ sandboxedr{rsubmultruedivfloordivpowmodrdtDictr7CallableAny__annotations__posnegre frozensetrf FrozenSetrgrkboolruryr rrUnionr rrxrTupleOptionalrr __classcell__rqs@r9r^r^sI \ \ \  l \KKQZ0E%F FG\ \CCsAJw~$>>?&,59;; C(666+4)++q{3'5559ae9qu9999999 NQUN#NaeNNNNN  AE  d      7 7*- 756U 7CD5 7  7 7 7 7..C.ae.....656$%GCJ$76  ! "6666.7157S7QWQUI=M5N7777" AE c i    /3  gaeSj!sAEz"  Z +  :66u6u 6 % 6  66666666r;r^cHeZdZdZdejdedejdeffd ZxZ S)ImmutableSandboxedEnvironmentzWorks exactly like the regular `SandboxedEnvironment` but does not permit modifications on the builtin mutable objects `list`, `set`, and `dict` by using the :func:`modifies_known_mutable` function. r8rHrrr-cpt|||sdSt|| S)NF)rjrur\)rpr8rHrrrqs r9ruz/ImmutableSandboxedEnvironment.is_safe_attributes9ww((dE:: 5)#t4444r;) r5rrrrrr7rrurrs@r9rrsg 5QU5#5ae55555555555r;rc eZdZdedejddffd Zdedejejdej eejfdej ejeffdZ xZ S) renvrhr-Nc H||_tjdi|dS)Nr)_envrjrk)rprrhrqs r9rkzSandboxedFormatter.__init__s- ""6"""""r; field_namer<ct|\}}||||}|D]>\}}|r|j||}#|j||}?||fSr)r get_valuerrxr) rprr<rhfirstrestr8is_attris r9 get_fieldzSandboxedFormatter.get_fields1<< tnnUD&11 0 0JGQ 0i''Q//i''Q//Ezr;) r5rrr rrrkr7SequenceMappingrrrrs@r9rrs#K#15#T######  %&Z%6 @A #qu*@U           r;rceZdZdS)rN)r5rrrr;r9rrsDr;r)9rr{r2typingr_stringr collectionsrrstringr markupsaferr environmentr exceptionsr runtimer r TypeVarrrrr@setrSetr7rrrTrVrW MutableSetrMutableMappingMutableSequencer+rTyperrr:intr>rCrGrrYr\r^rrrrr;r9rs ......&&&&&&$$$$$$%%%%%% AIcCJ/000  *-AE#J...(+suu!%*,,, *95 *95&/ $;!        EEEFF  MMMNN      1(B qwqwqvq{3'778#=>(((V AJ 1:c?     c e      a  A     "!qu"!C"!D"!"!"!"!JST2N6N6N6N6N6;N6N6N6b 5 5 5 5 5$8 5 5 5$     1?     r;