Skip to content

python false positive Clear-text logging of sensitive information #13538

Open

Description

@drobert

Description of the false positive

I have a python aws lambda that returns a json payload with correctly identified sensitive information (along with metadata like status code, etc.). I have a 'log response' function that specifically logs metadata and no sensitive data, but codeql is reporting that sensitive non-metadata fields are being logged.

Code samples or links to source code

def main():
  user_creds = ... // sensitive information here
  return write_access_log({
    "statusCode": 200,
    "body": {
      "dry_run": False,
      # actual sensitive information here
      "credentials": {
        "db": {
          "username": user_creds.username,
          "privatekey": user_creds.encrypted_private_key,
          "passphrase": user_creds.private_key_passphrase,
        }
      }
    }
  })
  
def write_access_log(resp):
  if "statusCode" in resp:
    dry_run = (
      str(resp["body"]["dry_run"])
      if resp.get("body", {}).get("dry_run") is not None
      else "unknown"
    )
    payload = {"statusCode": int(resp["statusCode"]), "dry_run": dry_run}
    msg = json.dumps(payload)
    # Flagged as 'clear-text logging of sensitive information', showing a path that includes 
    # "passphrase" from resp which is not logged
    logger.info(msg)
        
  return resp

Activity

  1. aibaars commented on Jun 23, 2023

    @aibaars
    Contributor

    Thanks for reporting. It looks like you're right. It may be that the analysis is not precise enough and simply assumes that reading an attribute of an object that contains some sensitive data will return the sensitive information. I'll ask the team to have a look, hopefully the analysis can be made more precise.

  2. yoff commented on Jun 23, 2023

    @yoff
    Contributor

    Indeed this is something we are slowly getting to a position where we can improve the precision.

  3. dmartin-isp commented on Jul 1, 2025

    @dmartin-isp

    I just got flagged with Clear-text logging of sensitive information because I pulled down some json from the web, copied a field into a var and logged the var. It was a "stream_id", not a password, not sensitive at all.

    I would love to know how to appease the bot. I'm a bit dismayed that there weren't instructions beyond "only log literals", which doesn't make sense. Would scanning the var with a regex make it happy? Is there some way to mark things as not sensitive? I can't imagine the intent is that no one log things they got from web interfaces.

    I fear overzealous false positives will result in people muting the scan, rather than improving code.

    Thank you!

  4. rinerb commented on Aug 5, 2025

    @rinerb

    This seems to flag printing/logging any variable with "secret" in the name, and any variable set from a variable with "secret" in the name. I have code to work with AWS secrets manager and have lots of variables with "secret" in the name but never actually print the secret value. It's just a lot of false positives.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions