Skip to content

Commit 4a14f25

Browse files
authored
Merge pull request #93 from Miyamura80/fix/security-audit-fixes
🐛 Fix security issues in logging and config loading
2 parents 3e22fe1 + 7c2dcdd commit 4a14f25

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

common/global_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def recursive_update(default: dict, override: dict) -> dict:
7575
for split_file in split_files:
7676
if split_file.name in reserved_filenames:
7777
continue
78+
# Security: skip symlinks to prevent loading files outside common/
79+
if split_file.is_symlink():
80+
logger.warning(f"Skipping symlink config file: {split_file}")
81+
continue
7882
root_key = split_file.stem
7983
if root_key in config_data:
8084
raise KeyError(

src/utils/logging_config.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,19 @@ def scrub_sensitive_data(record):
9191
scrubbed_value_str = _SCRUBBER.scrub(value_str)
9292

9393
if scrubbed_value_str != value_str:
94-
# Re-instantiate the exception with the redacted message to preserve loguru formatting
94+
# Modify args in-place to preserve exception type and metadata
95+
# Most exceptions store their message in args[0]
9596
try:
96-
# Most standard exceptions accept a single string argument
97-
new_value = type_(scrubbed_value_str)
98-
except TypeError:
99-
# Fallback to a generic Exception if type instantiation fails
100-
# (e.g., some exceptions require specific constructor arguments)
101-
new_value = Exception(f"[{type_.__name__}] {scrubbed_value_str}")
102-
103-
# Preserve traceback and context metadata
104-
new_value.__traceback__ = tb
105-
new_value.__cause__ = getattr(value, "__cause__", None)
106-
new_value.__context__ = getattr(value, "__context__", None)
107-
108-
record["exception"] = (type_, new_value, tb)
97+
if value.args:
98+
scrubbed_args = tuple(
99+
_SCRUBBER.scrub(str(arg)) if isinstance(arg, str) else arg
100+
for arg in value.args
101+
)
102+
value.args = scrubbed_args
103+
except (AttributeError, TypeError):
104+
# If args modification fails, leave original exception unchanged
105+
# This is safer than creating a mismatched exception type
106+
pass
109107

110108
# Scrub extra context if present
111109
extra = record.get("extra")

0 commit comments

Comments
 (0)