skills/output-filter-pattern/SKILL.md
Security pattern for filtering data before sending to external entities. Use when preventing excessive data exposure, implementing data minimization, protecting sensitive information in API responses, or ensuring clients receive only necessary data. Addresses "Entity receives excessive data" problem and OWASP API3:2019 Excessive Data Exposure.
npx skillsauth add igbuend/grimbard output-filter-patternInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Filter data before sending it to an external entity, ensuring that only necessary and authorized data elements are transmitted. This prevents excessive data exposure and enforces data minimization.
Entity receives excessive data: System sends more data than the receiver needs or is authorized to see, leading to:
Never rely on the client to filter sensitive data.
Data filtering must occur at the server/API level before sending, not at the client level after receiving.
| Attack Vector | Description | |---------------|-------------| | Traffic sniffing | Attackers intercept API responses before client filtering | | Direct API calls | Attackers bypass client applications entirely | | Client manipulation | Attackers modify client code to reveal hidden data | | Mobile app reverse engineering | Attackers extract API endpoints and call directly |
| Role | Type | Responsibility | |------|------|----------------| | Sender | Entity | System that sends data | | Output Filter | Enforcement Point | Filters outgoing data | | Filter Specification | Information Point | Defines what data to include/exclude | | Receiver | Entity | External entity receiving data |
Sender → [raw_data] → Output Filter
Output Filter → [get_filter_spec(context)] → Filter Specification
Filter Specification → [filter_spec] → Output Filter
Output Filter → [apply filter to raw_data] → Output Filter
Output Filter → [filtered_data] → Receiver
Explicitly define which fields to include:
Include: [id, name, email, created_at]
// All other fields excluded by default
Define which fields to exclude:
Exclude: [ssn, password_hash, internal_id, credit_card]
// All other fields included by default
Warning: Blocklists fail when new sensitive fields are added but not blocked.
Different filters based on:
Define explicit response schemas for each endpoint:
Create specific response objects:
// Instead of returning database entity directly
User (DB) → UserResponseDTO (filtered)
UserResponseDTO {
id, name, email, avatar_url
// Excludes: password_hash, ssn, internal_flags
}
Query only needed fields from data source:
SELECT id, name, email FROM users
// Instead of SELECT * FROM users
Custom serializers per context:
Never use generic methods that expose all properties:
// AVOID
return user.to_json()
return user.to_dict()
return serialize(user)
// PREFER
return {
'id': user.id,
'name': user.name,
'email': user.email
}
Data exposure often occurs in nested/related objects:
// User response includes related data
{
"id": 1,
"name": "Alice",
"manager": {
"id": 2,
"name": "Bob",
"salary": 150000 // LEAK! Manager salary exposed
}
}
Filter nested objects recursively.
Don't leak data in error messages:
Even metadata can leak information:
Ensure consistent filtering across:
| Category | Sensitive Fields | |----------|------------------| | Authentication | password_hash, auth_tokens, API keys, session_ids | | Personal (PII) | SSN, tax_id, credit_card, bank_account | | Internal | internal_id, debug_flags, feature_flags | | System | created_by_system, internal_notes, audit_data | | Relationships | Detailed data of related entities | | Metadata | IP addresses, user agents, timestamps (if sensitive) |
Both are required. User may be authorized to see a resource but not all its properties.
Complementary patterns for complete data flow security.
development
Security anti-pattern for Cross-Site Scripting vulnerabilities (CWE-79). Use when generating or reviewing code that renders HTML, handles user input in web pages, uses innerHTML/document.write, or builds dynamic web content. Covers Reflected, Stored, and DOM-based XSS. AI code has 86% XSS failure rate.
development
Security anti-pattern for XPath injection vulnerabilities (CWE-643). Use when generating or reviewing code that queries XML documents, constructs XPath expressions, or handles user input in XML operations. Detects unescaped quotes and special characters in XPath queries.
development
Security anti-pattern for weak password hashing (CWE-327, CWE-759). Use when generating or reviewing code that stores or verifies user passwords. Detects use of MD5, SHA1, SHA256 without salt, or missing password hashing entirely. Recommends bcrypt, Argon2, or scrypt.
development
Security anti-pattern for weak encryption (CWE-326, CWE-327). Use when generating or reviewing code that encrypts data, handles encryption keys, or uses cryptographic modes. Detects DES, ECB mode, static IVs, and custom crypto implementations.