Clear-text storage of sensitive data

Clear-text storage of sensitive data

Description

Anyone who can read a plaintext file or serialized record can read the passwords, API keys, or tokens it contains.

Potential impact

Credentials copied into backups, logs, or temporary files may remain usable long after the original file is removed.

Remediation

For password verification, store an Argon2id, bcrypt, or PBKDF2 hash. Keep reusable credentials in a secret store and put only a reference in JSON or YAML. If you must store a retrievable secret yourself, encrypt it with a trusted library and manage the key separately.

Examples

Before

python
from pathlib import Path
from flask import request

def bad_password_file():
    password = request.args.get("password")
    Path("/var/app/password.txt").write_text(password)

After

python
from argon2 import PasswordHasher

def safe_password_hash(password):
    return PasswordHasher().hash(password)

PasswordHasher().hash(password) returns a hash for the caller to store. The revised function does not write the plaintext password or the hash to disk.

References