# Cwe 359 Privacy Violation

> Use this skill when you need to remediate CWE-359 (Privacy Violation) vulnerabilities in Java code. Triggers on SAST findings, security reviews, or when fixing privacy violation issues.

- Skill: `developerscoffee/cwe-359-privacy-violation` (Agent Skill)
- Install (CLI): `npx skillmds@latest add developerscoffee/cwe-359-privacy-violation`
- Raw SKILL.md: https://api.skillmd.com/api/skills/developerscoffee/cwe-359-privacy-violation/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Security
- License: MIT
- Author: DevelopersCoffee (https://skillmd.com/u/developerscoffee)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/developerscoffee/cwe-359-privacy-violation

---


# CWE-359 Privacy Violation

## Description

Privacy Violation

Reference:
https://cwe.mitre.org/data/definitions/359.html


**OWASP Category**: A02:2021 – Cryptographic Failures


---

## Vulnerable Pattern


### ❌ Example 1: Vulnerable Pattern

```java
// VULNERABLE: PII exposed in logs
log.info("User login: " + user.getEmail() + ", SSN: " + user.getSsn());

// VULNERABLE: PII in API response
return new UserResponse(user.getName(), user.getSsn(), user.getAddress());
```


**Why it's vulnerable:** This pattern is vulnerable to Privacy Violation




---

## Deterministic Fix


### ✅ Secure Implementation: Secure Implementation

```java
// SECURE: Mask PII in logs
log.info("User login: {}", maskEmail(user.getEmail()));

// SECURE: Only expose necessary data, mask sensitive fields
public UserResponse toResponse(User user) {
    return UserResponse.builder()
        .name(user.getName())
        .email(maskEmail(user.getEmail()))
        .ssnLast4(user.getSsn().substring(user.getSsn().length() - 4))
        .build();
}

private String maskEmail(String email) {
    int at = email.indexOf('@');
    return email.charAt(0) + "***" + email.substring(at);
}
```


**Why it's secure:** Implements proper protection against Privacy Violation




---

## Detection Pattern

Look for these patterns in your codebase:


```bash
# Find PII in logs
grep -rn "log.*ssn\\|log.*email\\|log.*password" --include="*.java"
```



---

## Remediation Steps


1. Identify all PII fields (SSN, email, address, etc.)

2. Mask PII in logs

3. Return minimal data in API responses

4. Implement data minimization principles


---

## Key Imports

```java

```

---

## Verification

After remediation:


- Run SAST scanner to confirm vulnerability is resolved

- Review all instances of the vulnerable pattern

- Add unit tests that verify the secure implementation

- Check for similar patterns in related code


---

## Trigger Examples

```
Fix CWE-359 vulnerability
Resolve Privacy Violation issue
Secure this Java code against privacy violation
SAST reports CWE-359
```

---

## Common Vulnerable Locations

| Layer | Files | Patterns |
|-------|-------|----------|

| Controller | `*Controller.java` | User input handling |

| Service | `*Service.java` | Business logic |

| Repository | `*Repository.java` | Data access |


---

## References


- [CWE-359: Privacy Violation](https://cwe.mitre.org/data/definitions/359.html)


---

**Source**: Generated by [Java CWE Security Skills Generator](https://github.com/DevelopersCoffee/java-cwe-security-skills)
**Last Updated**: 2026-03-07

