1111from .._iast_request_context_base import get_hash_object_tracking
1212from .._iast_request_context_base import is_iast_request_enabled
1313from .._iast_request_context_base import set_hash_object_tracking
14+ from .._logs import iast_error
1415from .._metrics import _set_metric_iast_executed_sink
1516from .._metrics import _set_metric_iast_instrumented_sink
1617from .._patch_modules import WrapFunctonsForIAST
@@ -120,26 +121,32 @@ def wrapped_init_function(wrapped: Callable, instance: Any, args: Any, kwargs: A
120121 res = wrapped .__func__ (instance , * args , ** kwargs )
121122 else :
122123 res = wrapped (* args , ** kwargs )
123- if is_iast_request_enabled ():
124- set_hash_object_tracking (res , kwargs .get ("usedforsecurity" , None ) is False )
124+ try :
125+ if is_iast_request_enabled ():
126+ set_hash_object_tracking (res , kwargs .get ("usedforsecurity" , None ) is False )
127+ except Exception as e :
128+ iast_error ("propagation::sink_point::Error in weak_hash.wrapped_init_function" , e )
125129 return res
126130
127131
128132def wrapped_digest_function (wrapped : Callable , instance : Any , args : Any , kwargs : Any ) -> Any :
129- if is_iast_request_enabled ():
130- if (
131- WeakHash .has_quota ()
132- and instance .name .lower () in get_weak_hash_algorithms ()
133- and get_hash_object_tracking (instance ) is False
134- ):
135- WeakHash .report (
136- evidence_value = instance .name ,
137- )
138-
139- # Reports Span Metrics
140- increment_iast_span_metric (IAST_SPAN_TAGS .TELEMETRY_EXECUTED_SINK , WeakHash .vulnerability_type )
141- # Report Telemetry Metrics
142- _set_metric_iast_executed_sink (WeakHash .vulnerability_type )
133+ try :
134+ if is_iast_request_enabled ():
135+ if (
136+ WeakHash .has_quota ()
137+ and instance .name .lower () in get_weak_hash_algorithms ()
138+ and get_hash_object_tracking (instance ) is False
139+ ):
140+ WeakHash .report (
141+ evidence_value = instance .name ,
142+ )
143+
144+ # Reports Span Metrics
145+ increment_iast_span_metric (IAST_SPAN_TAGS .TELEMETRY_EXECUTED_SINK , WeakHash .vulnerability_type )
146+ # Report Telemetry Metrics
147+ _set_metric_iast_executed_sink (WeakHash .vulnerability_type )
148+ except Exception as e :
149+ iast_error ("propagation::sink_point::Error in weak_hash.wrapped_digest_function" , e )
143150
144151 if hasattr (wrapped , "__func__" ):
145152 return wrapped .__func__ (instance , * args , ** kwargs )
@@ -155,31 +162,37 @@ def wrapped_sha1_function(wrapped: Callable, instance: Any, args: Any, kwargs: A
155162
156163
157164def wrapped_new_function (wrapped : Callable , instance : Any , args : Any , kwargs : Any ) -> Any :
158- if is_iast_request_enabled ():
159- if WeakHash .has_quota () and args [0 ].lower () in get_weak_hash_algorithms ():
160- WeakHash .report (
161- evidence_value = args [0 ].lower (),
162- )
163- # Reports Span Metrics
164- increment_iast_span_metric (IAST_SPAN_TAGS .TELEMETRY_EXECUTED_SINK , WeakHash .vulnerability_type )
165- # Report Telemetry Metrics
166- _set_metric_iast_executed_sink (WeakHash .vulnerability_type )
165+ try :
166+ if is_iast_request_enabled ():
167+ if WeakHash .has_quota () and args [0 ].lower () in get_weak_hash_algorithms ():
168+ WeakHash .report (
169+ evidence_value = args [0 ].lower (),
170+ )
171+ # Reports Span Metrics
172+ increment_iast_span_metric (IAST_SPAN_TAGS .TELEMETRY_EXECUTED_SINK , WeakHash .vulnerability_type )
173+ # Report Telemetry Metrics
174+ _set_metric_iast_executed_sink (WeakHash .vulnerability_type )
175+ except Exception as e :
176+ iast_error ("propagation::sink_point::Error in weak_hash.wrapped_new_function" , e )
167177
168178 if hasattr (wrapped , "__func__" ):
169179 return wrapped .__func__ (instance , * args , ** kwargs )
170180 return wrapped (* args , ** kwargs )
171181
172182
173183def wrapped_function (wrapped : Callable , evidence : str , instance : Any , args : Any , kwargs : Any ) -> Any :
174- if is_iast_request_enabled ():
175- if WeakHash .has_quota ():
176- WeakHash .report (
177- evidence_value = evidence ,
178- )
179- # Reports Span Metrics
180- increment_iast_span_metric (IAST_SPAN_TAGS .TELEMETRY_EXECUTED_SINK , WeakHash .vulnerability_type )
181- # Report Telemetry Metrics
182- _set_metric_iast_executed_sink (WeakHash .vulnerability_type )
184+ try :
185+ if is_iast_request_enabled ():
186+ if WeakHash .has_quota ():
187+ WeakHash .report (
188+ evidence_value = evidence ,
189+ )
190+ # Reports Span Metrics
191+ increment_iast_span_metric (IAST_SPAN_TAGS .TELEMETRY_EXECUTED_SINK , WeakHash .vulnerability_type )
192+ # Report Telemetry Metrics
193+ _set_metric_iast_executed_sink (WeakHash .vulnerability_type )
194+ except Exception as e :
195+ iast_error ("propagation::sink_point::Error in weak_hash.wrapped_function" , e )
183196
184197 if hasattr (wrapped , "__func__" ):
185198 return wrapped .__func__ (instance , * args , ** kwargs )
0 commit comments