Sensitive Data Storage: Encryption, Caching, and Cookies

CWE-256, CWE-311, CWE-312, CWE-313, CWE-316, CWE-522, CWE-525, CWE-539, CWE-598

Multiple vulnerabilities related to how applications store and cache sensitive data:

Together, they expose sensitive data through multiple storage mechanisms.


Real-World Attack Scenarios

Scenario 1: Plaintext Passwords in Database

A user management system stores passwords in plaintext:

-- Database table
CREATE TABLE users (
    id INT PRIMARY KEY,
    username VARCHAR(255),
    password VARCHAR(255)  -- CLEARTEXT!
);

-- Sample data
INSERT INTO users VALUES (1, 'admin', 'admin123');
INSERT INTO users VALUES (2, 'user1', 'password456');

The vulnerability:

Passwords stored as plaintext:

  • Database breach exposes all passwords

  • No effort required to read them

  • Attacker has access to all accounts immediately

The attack:

Attacker gains database access (SQL injection, misconfiguration, insider threat):

Attacker now has:

  • All user passwords

  • Access to all accounts

  • Ability to login as any user

  • Ability to reset other passwords

  • Complete system compromise

Result:

  • Complete authentication bypass

  • All accounts compromised

  • Attacker access to all data

  • Reputation damage

  • PCI DSS violation ($100K+ fines)

Finding it: Gain database access. Query user table. Check if passwords are plaintext or hashed.


Scenario 2: Unencrypted Payment Information

E-commerce site stores credit card information unencrypted:

The vulnerability:

Credit cards stored without encryption:

  • Database breach exposes all cards

  • PCI DSS explicitly prohibits this

  • Massive fines and liability

The attack:

Attacker gains database access:

Attacker uses cards for fraud:

Result:

  • Massive financial fraud

  • PCI DSS violation ($100K-$1M+ fines)

  • Lawsuits from affected customers

  • Company reputation destroyed

Finding it: Access database. Check if payment data encrypted. Look for plaintext card numbers.


Scenario 3: API Keys in Browser Cache

Web application caches pages with API keys:

The vulnerability:

Page cached in browser, disk, and intermediate proxies:

  • Browser cache contains the secret

  • Anyone with access to computer can retrieve it

  • Network proxies cache the page

  • Page history contains the URL

The attack:

Attacker:

  1. Uses victim's computer

  2. Opens browser cache: ~/.cache/ (Linux) or %TEMP% (Windows)

  3. Finds cached HTML with API key

  4. Extracts API key

  5. Uses it to access APIs

Or:

Result:

  • API key theft

  • Unauthorized API access

  • Data exfiltration

  • Complete API compromise

Finding it: Access cached pages. Check if sensitive data visible in cache. Use browser cache analysis tools.


Scenario 4: Session Tokens in Persistent Cookies

Application stores session tokens in persistent cookies:

The vulnerability:

Session token in persistent cookie:

  • Survives browser restart

  • Stored on disk in plaintext

  • Can be extracted from disk

  • Long-lived cookie = longer attack window

The attack:

Attacker:

  1. Gains access to victim's computer

  2. Extracts cookie from disk

  3. Uses cookie in their own browser

  4. Impersonates victim indefinitely

  5. Token valid for entire year

Result:

  • Session hijacking

  • Long-term account compromise

  • Indefinite impersonation

Finding it: Check cookie storage. Verify expiration. Look for session tokens in persistent cookies.


Scenario 5: Sensitive Data in URL Query String

Application passes sensitive data in URLs:

The vulnerability:

URL parameters are logged and cached:

  • Web server access logs contain URLs

  • Browser history contains URLs

  • Proxy logs contain URLs

  • Referrer headers leak URLs

  • URLs visible in browser address bar

The attack:

Attacker accesses:

  1. Web server logs: tail /var/log/apache2/access.log | grep credit_card

  2. Browser history: victim's browser contains URL with data

  3. Proxy logs: network proxies log all traffic

  4. Referrer headers: other sites receive referrer with data

All containing sensitive information.

Result:

  • Credential exposure

  • Data leakage

  • Privacy violation

Finding it: Intercept requests. Monitor for sensitive data in URLs. Check logs for exposed data.


Scenario 6: Secrets in Memory Without Clearing

Passwords loaded into memory and never cleared:

The vulnerability:

Sensitive data left in memory:

  • Memory dumps (crash, core dumps) contain password

  • Debuggers can inspect memory

  • Process monitoring tools see memory

  • Garbage collection doesn't immediately clear memory

The attack:

Attacker:

  1. Crashes application (trigger error)

  2. Core dump written to disk containing password

  3. Or attaches debugger to running process

  4. Inspects memory containing password

  5. Extracts plaintext password

Result:

  • Plaintext password extraction

  • Account compromise

  • Authentication bypass

Finding it: Trigger memory dumps. Use memory analysis. Check if sensitive data cleared from memory.


Scenario 7: Credentials in Config Files

Application stores credentials in plaintext config files:

The vulnerability:

Credentials in plaintext files:

  • Version control exposes them

  • Backups contain them

  • File system access reveals them

  • Logs might include them

The attack:

Attacker:

  1. Clones repository: git clone https://repo.git

  2. Finds config.ini with credentials

  3. Uses credentials to access database, AWS, Stripe, etc.

Or:

Result:

  • Complete credential exposure

  • Access to database, AWS, external services

  • Complete system compromise

Finding it: Search for config files. Check for plaintext credentials. Review git history for committed secrets.


How to Identify Sensitive Data Storage Issues During Testing

1. Test password storage

2. Test payment data storage

Check if credit cards stored encrypted:

3. Check browser cache

Look for pages containing sensitive data.

4. Check cookies

Developer Tools → Application → Cookies Look for:

  • Plaintext tokens

  • Sensitive information

  • Long expiration dates

  • Missing security flags

5. Check URLs

Intercept with Burp Suite:

  • Look for sensitive data in URLs

  • Check if data logged somewhere

6. Check memory

Trigger crashes, analyze memory dumps for plaintext passwords.

7. Check config files


Mitigation Strategies

Never store passwords plaintext

Always hash with bcrypt or Argon2:

Encrypt sensitive data at rest

Never cache sensitive pages

Use secure cookies

Never put sensitive data in URLs

Use POST instead:

Clear sensitive data from memory

Never commit secrets to git

Use secrets management systems

  • AWS Secrets Manager

  • Azure Key Vault

  • HashiCorp Vault

  • Kubernetes Secrets


Last updated