Skip to content

Mask plaintext Mediator API keys in cwrap.py and pwrap.py debug logs #624

Open

Description

@Somya-jain0811

While reviewing the distributed study wrappers in tools/cwrap.py and tools/pwrap.py, I noticed that when DEBUG logging is enabled, the scripts print the raw Mediator API key directly into the logs:

  • In tools/cwrap.py (L74): logging.debug(f"API Key: {apikey}")
  • In tools/cwrap.py (L100): logs the full request URL containing the unmasked key: logging.debug(f'https://www.controlcore.org/pm/{yuyu}{apikey}&fetch={name2}')
  • In tools/pwrap.py (L65): logging.debug(f"API Key: {apikey}")

Why this is an issue

In multi-node study runs or shared lab/CI environments, debug logs often get aggregated into files or terminal logs. Having the raw API key from concore.apikey exposed in plaintext creates an unnecessary credential leak.

Proposed fix

Instead of removing the log line completely (which would make it harder for researchers to verify whether an API key was actually loaded), we can add a lightweight masking helper that redacts all but the last 4 characters (e.g. ******1234 or **** for short keys), and sanitize the logged request URLs.

I have already implemented and tested this locally along with unit tests. Happy to open a PR for this if the maintainers agree!

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions