fix: mask Component Secrets in trace logs (#8204)
Co-authored-by: psy42a <17905361+psy42a@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
parent
c8ac453601
commit
93517fa3b6
1 changed files with 14 additions and 4 deletions
|
|
@ -275,10 +275,19 @@ class TracingService(Service):
|
|||
@staticmethod
|
||||
def _cleanup_inputs(inputs: dict[str, Any]):
|
||||
inputs = inputs.copy()
|
||||
for key in inputs:
|
||||
if "api_key" in key:
|
||||
inputs[key] = "*****" # avoid logging api_keys for security reasons
|
||||
return inputs
|
||||
sensitive_keywords = {"api_key", "password", "server_url"}
|
||||
|
||||
def _mask(obj: Any):
|
||||
if isinstance(obj, dict):
|
||||
return {
|
||||
k: "*****" if any(word in k.lower() for word in sensitive_keywords) else _mask(v)
|
||||
for k, v in obj.items()
|
||||
}
|
||||
if isinstance(obj, list):
|
||||
return [_mask(i) for i in obj]
|
||||
return obj
|
||||
|
||||
return _mask(inputs)
|
||||
|
||||
def _start_component_traces(
|
||||
self,
|
||||
|
|
@ -344,6 +353,7 @@ class TracingService(Service):
|
|||
if component._vertex:
|
||||
trace_id = component._vertex.id
|
||||
trace_type = component.trace_type
|
||||
inputs = self._cleanup_inputs(inputs)
|
||||
component_trace_context = ComponentTraceContext(
|
||||
trace_id, trace_name, trace_type, component._vertex, inputs, metadata
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue