Skip to content

Commit a6b0958

Browse files
committed
fix(security): mask secrets via dataclass-field iteration to clear CodeQL alert
1 parent 15f1c41 commit a6b0958

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/config.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,12 @@ def setup_logging(debug: bool = False) -> None:
549549
# .env import test.
550550
cfg2 = import_from_env(cfg)
551551
print("After import_from_env (may be no-op):")
552-
# Collect only the NAMES of populated secret fields; the secret values
553-
# themselves never flow into the print (avoids clear-text logging).
554-
configured = {name for name in _SECRET_FIELDS if getattr(cfg2, name)}
555-
for f_name in sorted(_SECRET_FIELDS):
556-
print(f" {f_name} = {'set' if f_name in configured else '(empty)'}")
552+
# Iterate dataclass fields (not the _SECRET_FIELDS literal) and mask secrets;
553+
# the secret value only gates a constant, so it never reaches the print.
554+
for f in fields(AppConfig):
555+
if f.name in _SECRET_FIELDS:
556+
masked = "***" if getattr(cfg2, f.name) else "(empty)"
557+
print(f" {f.name} = {masked}")
557558

558559
print()
559560
print("Config module OK")

0 commit comments

Comments
 (0)