Security

What is Improper Removal of Sensitive (CWE-212)?

Learn how to prevent Improper Removal of Sensitive Information Before Storage or Transfer (CWE-212) in your applications and protect sensitive data from...

SP
Shreya Pillai July 28, 2026 5 min read Security
AI-friendly summary

What it is: Improper Removal of Sensitive Information Before Storage or Transfer (CWE-212) is a security vulnerability that occurs when sensitive information is not properly removed before storage or transfer, allowing unauthorized actors to access it.

Why it matters: CWE-212 can lead to confidentiality breaches, integrity violations, and availability disruptions. It's essential to detect and prevent this vulnerability to ensure the security of your application and sensitive data.

How to fix it: To fix CWE-212, implement proper data sanitization, use secure storage mechanisms, and ensure that sensitive information is not transmitted or stored in cleartext.

TL;DR: Improper Removal of Sensitive Information Before Storage or Transfer (CWE-212) occurs when sensitive information is not properly removed before storage or transfer, allowing unauthorized actors to access it. To fix CWE-212, implement proper data sanitization, use secure storage mechanisms, and ensure that sensitive information is not transmitted or stored in cleartext.

Field Value
CWE ID CWE-212
OWASP Category A05:2025 - Security Misconfiguration
CAPEC CAPEC-168
Typical Severity High
Affected Technologies Java, Python, Node.js, PHP
Detection Difficulty Moderate
Last Updated 2026-07-28

What is Improper Removal of Sensitive Information Before Storage or Transfer?

Improper Removal of Sensitive Information Before Storage or Transfer (CWE-212) is a type of security vulnerability that occurs when sensitive information is not properly removed before storage or transfer, allowing unauthorized actors to access it. As defined by the MITRE Corporation under CWE-212, and classified by the OWASP Foundation under A05:2025 - Security Misconfiguration, this vulnerability can lead to confidentiality breaches, integrity violations, and availability disruptions.

Quick Summary

Improper Removal of Sensitive Information Before Storage or Transfer (CWE-212) is a critical security vulnerability that occurs when sensitive information is not properly removed before storage or transfer. This vulnerability can lead to confidentiality breaches, integrity violations, and availability disruptions. To detect and prevent CWE-212, implement proper data sanitization, use secure storage mechanisms, and ensure that sensitive information is not transmitted or stored in cleartext.

Jump to: Quick Summary · Improper Removal of Sensitive Information Before Storage or Transfer Overview · How Improper Removal of Sensitive Information Before Storage or Transfer Works · Business Impact of Improper Removal of Sensitive Information Before Storage or Transfer · Improper Removal of Sensitive Information Before Storage or Transfer Attack Scenario · How to Detect Improper Removal of Sensitive Information Before Storage or Transfer · How to Fix Improper Removal of Sensitive Information Before Storage or Transfer · Framework-Specific Fixes for Improper Removal of Sensitive Information Before Storage or Transfer · How to Ask AI to Check Your Code for Improper Removal of Sensitive Information Before Storage or Transfer · Improper Removal of Sensitive Information Before Storage or Transfer Best Practices Checklist · Improper Removal of Sensitive Information Before Storage or Transfer FAQ · Vulnerabilities Related to Improper Removal of Sensitive Information Before Storage or Transfer · References · Scan Your Own Site

Improper Removal of Sensitive Information Before Storage or Transfer Overview

Improper Removal of Sensitive Information Before Storage or Transfer (CWE-212) occurs when sensitive information is not properly removed before storage or transfer, allowing unauthorized actors to access it. This can happen in various scenarios, including:

  • What: CWE-212 involves the improper removal of sensitive information from a resource before it is stored or transferred.
  • Why it matters: CWE-212 can lead to confidentiality breaches, integrity violations, and availability disruptions.
  • Where it occurs: CWE-212 can occur in any application that stores or transfers sensitive information.
  • Who is affected: Any user who has access to the sensitive information can be affected by CWE-212.
  • Who is NOT affected: Applications that never construct paths/queries/commands from external input are not affected by CWE-212.

How Improper Removal of Sensitive Information Before Storage or Transfer Works

Root Cause

The root cause of CWE-212 is the improper removal of sensitive information before storage or transfer. This can happen due to various reasons, including:

  • Insufficient data sanitization
  • Inadequate secure storage mechanisms
  • Transmission or storage of sensitive information in cleartext

Attack Flow

  1. An attacker gains access to the application’s sensitive information.
  2. The attacker exploits the vulnerability by accessing the sensitive information without proper removal.
  3. The attacker uses the accessed sensitive information for malicious purposes.

Prerequisites to Exploit

  • The application must store or transfer sensitive information.
  • The application must not properly remove sensitive information before storage or transfer.
  • The attacker must gain access to the application’s sensitive information.

Vulnerable Code

import os

# Vulnerable code: sensitive information is not properly removed before storage
def store_sensitive_info(info):
    with open('sensitive_info.txt', 'w') as f:
        f.write(info)

store_sensitive_info(os.environ['SENSITIVE_INFO'])

The vulnerable code above demonstrates the improper removal of sensitive information before storage. The os.environ dictionary is used to access sensitive information, which is then written to a file without proper sanitization.

Secure Code

import os

# Secure code: sensitive information is properly removed before storage
def store_sensitive_info(info):
    sanitized_info = sanitize(info)
    with open('sensitive_info.txt', 'w') as f:
        f.write(sanitized_info)

def sanitize(info):
    # Sanitize the sensitive information using a secure mechanism (e.g., hashing, encryption)
    return hash(info)

store_sensitive_info(os.environ['SENSITIVE_INFO'])

The secure code above demonstrates proper data sanitization before storage. The sanitize function uses a secure mechanism to remove sensitive information from the input.

Business Impact of Improper Removal of Sensitive Information Before Storage or Transfer

CWE-212 can lead to confidentiality breaches, integrity violations, and availability disruptions. The business impact of CWE-212 includes:

  • Confidentiality: Exposure of sensitive data
  • Integrity: Modification of sensitive information
  • Availability: Disruption of application services

The following are some real-world business consequences of CWE-212:

  • Financial losses due to data breaches
  • Compliance violations and regulatory fines
  • Reputation damage and loss of customer trust

Improper Removal of Sensitive Information Before Storage or Transfer Attack Scenario

Here is a step-by-step walkthrough of an attack scenario for CWE-212:

  1. An attacker gains access to the application’s sensitive information.
  2. The attacker exploits the vulnerability by accessing the sensitive information without proper removal.
  3. The attacker uses the accessed sensitive information for malicious purposes.

How to Detect Improper Removal of Sensitive Information Before Storage or Transfer

Manual Testing

  • Review the application’s code and configuration to identify potential CWE-212 vulnerabilities.
  • Test the application using manual testing techniques, such as fuzzing and black-box testing.

Automated Scanners (SAST/DAST)

  • Use automated scanners to detect CWE-212 vulnerabilities in the application’s code.
  • Note that static analysis may not catch all instances of CWE-212, as some vulnerabilities may require dynamic runtime testing.

PenScan Detection

  • PenScan’s scanner engines actively test for CWE-212 and other security vulnerabilities.
  • Use PenScan to detect CWE-212 in your application.

False Positive Guidance

  • Be aware that false positives can occur when using automated scanners or manual testing.
  • Verify the results of any detection tool or method to ensure accuracy.

How to Fix Improper Removal of Sensitive Information Before Storage or Transfer

Here are some steps to fix CWE-212:

  1. Implement proper data sanitization mechanisms, such as hashing or encryption.
  2. Use secure storage mechanisms, such as encrypted files or databases.
  3. Ensure that sensitive information is not transmitted or stored in cleartext.

Framework-Specific Fixes for Improper Removal of Sensitive Information Before Storage or Transfer

Here are some framework-specific fixes for CWE-212:

Java

import java.security.MessageDigest;

public class SecureStorage {
    public static String storeSensitiveInfo(String info) throws Exception {
        // Sanitize the sensitive information using a secure mechanism (e.g., hashing)
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        byte[] bytes = md.digest(info.getBytes());
        return bytes.toString();
    }
}

Node.js

const crypto = require('crypto');

function storeSensitiveInfo(info) {
    // Sanitize the sensitive information using a secure mechanism (e.g., hashing)
    const hash = crypto.createHash('sha256');
    hash.update(info);
    return hash.digest('hex');
}

module.exports.storeSensitiveInfo = storeSensitiveInfo;

Python/Django

import hashlib

def store_sensitive_info(info):
    # Sanitize the sensitive information using a secure mechanism (e.g., hashing)
    sanitized_info = hashlib.sha256(info.encode()).hexdigest()
    return sanitized_info

PHP

function storeSensitiveInfo($info) {
    // Sanitize the sensitive information using a secure mechanism (e.g., hashing)
    $hash = hash('sha256', $info);
    return $hash;
}

How to Ask AI to Check Your Code for Improper Removal of Sensitive Information Before Storage or Transfer

You can ask an AI coding assistant to review your code for potential CWE-212 vulnerabilities and provide recommendations for remediation. Here is a copy-pasteable prompt you can use:

Review the following Python/Django code block for potential CWE-212 Improper Removal of Sensitive Information Before Storage or Transfer vulnerabilities and rewrite it using secure storage mechanisms:

import os

# Vulnerable code: sensitive information is not properly removed before storage
def store_sensitive_info(info):
    with open('sensitive_info.txt', 'w') as f:
        f.write(info)

store_sensitive_info(os.environ['SENSITIVE_INFO'])

Improper Removal of Sensitive Information Before Storage or Transfer Best Practices Checklist

Here are some best practices to prevent CWE-212:

✅ Implement proper data sanitization mechanisms, such as hashing or encryption. ✅ Use secure storage mechanisms, such as encrypted files or databases. ✅ Ensure that sensitive information is not transmitted or stored in cleartext.

Improper Removal of Sensitive Information Before Storage or Transfer FAQ

How does Improper Removal of Sensitive Information Before Storage or Transfer occur?

Improper Removal of Sensitive Information Before Storage or Transfer (CWE-212) occurs when sensitive information is not properly removed before storage or transfer, allowing unauthorized actors to access it.

What are the consequences of Improper Removal of Sensitive Information Before Storage or Transfer?

The consequences of CWE-212 include exposure of sensitive data, which can lead to confidentiality breaches, integrity violations, and availability disruptions.

How do I detect CWE-212 in my application?

You can detect CWE-212 using manual testing, automated scanners (SAST/DAST), and PenScan’s detection capabilities.

What are the best practices for preventing CWE-212?

To prevent CWE-212, implement proper data sanitization, use secure storage mechanisms, and ensure that sensitive information is not transmitted or stored in cleartext.

Can AI help me detect and fix CWE-212 in my code?

Yes, you can ask an AI coding assistant to review your code for potential CWE-212 vulnerabilities and provide recommendations for remediation.

CWE-669 (Incorrect Resource Transfer Between Spheres) is a related weakness to CWE-212.

How can I protect my sensitive data from being exposed due to CWE-212?

You can protect your sensitive data by implementing proper access controls, using secure storage mechanisms, and ensuring that sensitive information is not transmitted or stored in cleartext.

Here are some related vulnerabilities to CWE-212:

CWE ID Name Relationship
CWE-669 Incorrect Resource Transfer Between Spheres ChildOf

References

Scan Your Own Site

Manual code review catches what you know to look for. An automated scan catches what you didn’t. Scan your own website using PenScan to find Improper Removal of Sensitive Information Before Storage or Transfer and other risks before an attacker does.