Skip to content

fix: mask Mediator API key in cwrap and pwrap debug logs - #625

Open
Somya-jain0811 wants to merge 1 commit into
ControlCore-Project:devfrom
Somya-jain0811:fix/mask-apikey-wrapper-logging
Open

Somya-jain0811 wants to merge 1 commit into
ControlCore-Project:devfrom
Somya-jain0811:fix/mask-apikey-wrapper-logging

Conversation

@Somya-jain0811

Copy link
Copy Markdown

Fixes #624

Summary

When running the remote wrapper nodes (tools/cwrap.py and tools/pwrap.py) with DEBUG logging enabled, the Mediator API key read from concore.apikey is logged in plaintext, both in the standalone API Key: line and embedded within the logged POST request URLs.

What was done

  1. Masking without losing debuggability: Rather than deleting the log lines completely, added mask_apikey(key) to both wrappers. It keeps only the last 4 characters visible (e.g. ******1234) and handles ?apikey= query strings. This prevents credential leaks in log files while still letting developers confirm that the key was detected.
  2. Import guard for testability: Wrapped the top-level script logic in def run() guarded by if __name__ == "__main__":. Previously, the file executed polling loops immediately at top level on import, which made it impossible to import into unit tests without triggering network requests or blocking.
  3. Unit tests: Added tests/test_wrapper_security.py with 17 tests covering empty/short/normal keys, query string variants, and using pytest's caplog to verify that raw secret strings never enter the logging stream.

Test results

All 17 tests pass cleanly:

tests/test_wrapper_security.py ................. [100%]
17 passed in 0.59s

Ready for review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant