references/frameworks.md
# Supported Regulatory Frameworks
Audit against the following frameworks. When the user does not specify which frameworks to check, audit against all of them and note which apply based on the nature of the codebase or business process.
## 1. GDPR (General Data Protection Regulation)
- Scope: Any system that processes personal data of EU/EEA residents
- Key Articles: Art. 5 (principles), Art. 6 (lawful basis), Art. 7 (consent), Art. 12-23 (data subject rights), Art. 25 (data protection by design), Art. 28 (processors), Art. 30 (records of processing), Art. 32 (security), Art. 33-34 (breach notification), Art. 35 (DPIA), Art. 44-49 (international transfers)
- Penalties: Up to 4% of annual global turnover or EUR 20 million
## 2. HIPAA (Health Insurance Portability and Accountability Act)
- Scope: Covered entities and business associates handling Protected Health Information (PHI)
- Key Rules: Privacy Rule, Security Rule (Administrative/Physical/Technical Safeguards), Breach Notification Rule, Enforcement Rule
- Key Standards: 164.308 (Administrative), 164.310 (Physical), 164.312 (Technical), 164.314 (Organizational), 164.316 (Policies/Documentation)
- Penalties: $100 to $50,000 per violation, up to $1.5 million per year per category
## 3. SOC 2 (Service Organization Control 2)
- Scope: Service organizations that store, process, or transmit customer data
- Trust Service Criteria: Security (CC1-CC9), Availability (A1), Processing Integrity (PI1), Confidentiality (C1), Privacy (P1)
- Common Criteria: CC1 (Control Environment), CC2 (Communication), CC3 (Risk Assessment), CC4 (Monitoring), CC5 (Control Activities), CC6 (Logical/Physical Access), CC7 (System Operations), CC8 (Change Management), CC9 (Risk Mitigation)
## 4. CCPA (California Consumer Privacy Act) / CPRA
- Scope: Businesses collecting personal information of California residents meeting revenue/data thresholds
- Key Rights: Right to Know, Right to Delete, Right to Opt-Out of Sale/Sharing, Right to Non-Discrimination, Right to Correct, Right to Limit Use of Sensitive PI
- Key Sections: 1798.100 (general duties), 1798.105 (deletion), 1798.110 (disclosure), 1798.115 (sale/sharing disclosure), 1798.120 (opt-out), 1798.121 (limit sensitive PI), 1798.125 (non-discrimination)
- Penalties: $2,500 per unintentional violation, $7,500 per intentional violation
## 5. PCI-DSS (Payment Card Industry Data Security Standard) v4.0
- Scope: Any entity that stores, processes, or transmits cardholder data
- Requirements: Req 1 (Network Security Controls), Req 2 (Secure Configurations), Req 3 (Protect Stored Account Data), Req 4 (Cryptography in Transit), Req 5 (Malware Protection), Req 6 (Secure Development), Req 7 (Restrict Access), Req 8 (Identify Users/Auth), Req 9 (Physical Access), Req 10 (Log/Monitor), Req 11 (Security Testing), Req 12 (Security Policies)
- Penalties: $5,000 to $100,000 per month of non-compliance, potential loss of card processing privileges
## Regulatory Reference Links
- GDPR Full Text: https://eur-lex.europa.eu/eli/reg/2016/679/oj
- HIPAA Security Rule: https://www.hhs.gov/hipaa/for-professionals/security/index.html
- SOC 2 Trust Service Criteria: https://us.aicpa.org/interestareas/frc/assuranceadvisoryservices/trustservicescriteria
- CCPA/CPRA Text: https://leginfo.legislature.ca.gov/faces/codes_displayText.xhtml?division=3.&part=4.&lawCode=CIV&title=1.81.5
- PCI-DSS v4.0: https://www.pcisecuritystandards.org/document_library/
references/scan-patterns.md
# Scan Categories and Search Patterns
For each category, document what was found, where it was found, and how it relates to each applicable framework. Many findings are about what is missing, not what is present, so actively check for the absence of required controls.
## 2.1 PII / Sensitive Data Handling
Scan for:
- Database schemas containing personal data fields (name, email, phone, address, SSN, DOB, IP address, device identifiers, biometric data, genetic data, health data, financial data, location data)
- Code that reads, writes, transforms, or transmits personal data
- Hardcoded personal data in source code, configuration files, or test fixtures
- Personal data in log output, error messages, or debug statements
- Data classification labels or lack thereof
- Data inventory or Records of Processing Activities (ROPA) documentation
Search patterns:
```
- Field names: email, phone, ssn, social_security, date_of_birth, dob, address, credit_card, card_number, cvv, pan, first_name, last_name, ip_address, device_id, location, latitude, longitude, biometric, health, diagnosis, prescription, medical
- Table/collection names: users, customers, patients, members, accounts, profiles, contacts, employees, cardholders, beneficiaries
- Code patterns: PII, PHI, personally_identifiable, protected_health, cardholder_data, sensitive_data
- File patterns: .env, .env.*, config.*, secrets.*, credentials.*, *.pem, *.key, *.cert
```
## 2.2 Data Retention
Scan for:
- Retention policies defined in code or documentation
- TTL (time-to-live) configurations on database records or cache entries
- Scheduled deletion jobs, data purge scripts, or archival processes
- Backup retention policies
- Log retention configurations
- Absence of retention policies (which is itself a finding)
- Data lifecycle management documentation
Search patterns:
```
- Keywords: retention, ttl, expire, expiry, expiration, purge, archive, delete_after, cleanup, data_lifecycle, retention_period, dispose, destroy
- Cron jobs or scheduled tasks related to data cleanup
- Database migration files that add or modify retention-related columns
- Configuration for log rotation and retention
```
## 2.3 Encryption
Scan for:
- Encryption at rest: database encryption, file encryption, disk encryption configuration
- Encryption in transit: TLS/SSL configuration, certificate management, HTTPS enforcement
- Key management: key storage, rotation policies, key derivation functions
- Cryptographic algorithm choices (flag weak algorithms: MD5, SHA1 for security purposes, DES, 3DES, RC4, RSA < 2048 bits, ECC < 256 bits)
- Password hashing algorithms (flag weak: MD5, SHA1, plain SHA256 without salt; approve: bcrypt, scrypt, Argon2, PBKDF2 with sufficient iterations)
- Secrets management (hardcoded secrets, environment variable handling, secrets vault integration)
- Certificate pinning in mobile or API client code
Search patterns:
```
- Keywords: encrypt, decrypt, cipher, aes, rsa, tls, ssl, https, certificate, cert, key_management, kms, vault, secret, hash, bcrypt, scrypt, argon2, pbkdf2, md5, sha1, sha256, hmac, salt, iv, nonce, padding
- Configuration: ssl_mode, sslmode, require_ssl, force_ssl, min_tls_version, cipher_suite
- Files: *.pem, *.key, *.cert, *.crt, *.pfx, *.p12, *.jks, *.keystore
```
## 2.4 Access Controls
Scan for:
- Authentication mechanisms (password policies, MFA/2FA, session management, token handling)
- Authorization models (RBAC, ABAC, ACLs, permission systems)
- Principle of least privilege implementation
- Service account management
- API key management and rotation
- Admin/superuser access controls and segregation
- Identity provider integration (SSO, SAML, OIDC, OAuth)
- Access review and recertification processes
- Default credentials or overly permissive configurations
Search patterns:
```
- Keywords: auth, authenticate, authorize, permission, role, rbac, abac, acl, access_control, privilege, admin, superuser, root, sudo, service_account, api_key, token, session, jwt, oauth, saml, oidc, sso, mfa, 2fa, totp, password_policy, login, logout
- Configuration: cors, allowed_origins, allowed_hosts, csrf, rate_limit, throttle, brute_force
- Middleware/decorators: @auth, @login_required, @requires_permission, @admin_only, requireAuth, isAuthenticated, checkPermission
```
## 2.5 Audit Logging
Scan for:
- Logging of authentication events (login, logout, failed attempts, password changes)
- Logging of authorization decisions (access granted, access denied)
- Logging of data access events (read, create, update, delete of regulated data)
- Logging of administrative actions (configuration changes, user management)
- Logging of data export or data transfer events
- Log integrity protection (tamper-evident logging, write-once storage, log signing)
- Log monitoring and alerting configuration
- Log aggregation and SIEM integration
- Absence of audit logging for critical operations
Search patterns:
```
- Keywords: audit, audit_log, audit_trail, event_log, activity_log, access_log, security_log, log_event, track, record_action, compliance_log, siem, splunk, datadog, cloudwatch, elastic
- Functions: logger, log.info, log.warn, log.error, audit.log, createAuditEntry, recordEvent, trackActivity
- Tables/collections: audit_logs, event_logs, activity_logs, access_logs, security_events
```
## 2.6 Consent Management
Scan for:
- Cookie consent implementation (banner, preference center, granular controls)
- Marketing consent collection and storage
- Privacy policy acceptance tracking
- Consent withdrawal mechanisms
- Purpose limitation enforcement (using data only for consented purposes)
- Consent versioning (tracking which version of terms/policy a user consented to)
- Age verification and parental consent (if processing minor's data)
- Legitimate interest assessments
- Double opt-in for email marketing
Search patterns:
```
- Keywords: consent, opt_in, opt_out, cookie_consent, cookie_banner, privacy_policy, terms_of_service, tos, gdpr_consent, marketing_consent, unsubscribe, preference, cookie_preference, purpose, legitimate_interest, dsar, data_subject, age_verification, parental_consent, double_opt_in
- Components/templates: CookieBanner, ConsentManager, PrivacyModal, OptOutForm, PreferenceCenter, UnsubscribeLink
- Database fields: consented_at, consent_version, marketing_opt_in, cookie_preferences, privacy_accepted
```
## 2.7 Data Transfer
Scan for:
- Cross-border data transfer mechanisms (Standard Contractual Clauses, adequacy decisions, Binding Corporate Rules, derogations)
- Third-party data sharing (analytics, advertising, subprocessors)
- API integrations that transmit regulated data
- Data export functionality
- Backup replication to other regions/jurisdictions
- CDN configuration and data caching locations
- Cloud provider region configuration
- Data Processing Agreements (DPAs) with subprocessors
- Transfer Impact Assessments (TIAs)
Search patterns:
```
- Keywords: transfer, export, share, third_party, subprocessor, vendor, analytics, tracking, pixel, beacon, cdn, region, jurisdiction, cross_border, scc, standard_contractual, adequacy, bcr, dpa, data_processing_agreement
- Services: google_analytics, segment, mixpanel, amplitude, hotjar, intercom, zendesk, stripe, twilio, sendgrid, mailchimp, aws_region, gcp_region, azure_region, cloudflare
- Configuration: region, availability_zone, data_residency, geo_restriction
```
## Scan Execution Rules
1. Be thorough. Search across all file types, not just source code. Include configuration files, infrastructure-as-code templates, documentation, CI/CD pipelines, Docker files, and dependency manifests.
2. Use multiple search strategies. Combine filename patterns, content patterns, and directory structure analysis. A single grep is never sufficient.
3. Check for absence. Actively check for the absence of required controls.
4. Note context. A finding in a test file has different significance than the same pattern in production code.
5. Follow the data. Trace regulated data from ingestion through processing to storage and deletion. Every touchpoint is a potential compliance checkpoint.
6. Check dependencies. Review package manifests (package.json, requirements.txt, Gemfile, go.mod, pom.xml) for libraries related to compliance functions (encryption, auth, logging, consent).
7. Review infrastructure. Check infrastructure-as-code files (Terraform, CloudFormation, Pulumi, Ansible, Kubernetes manifests) that define security controls, network isolation, encryption settings, and access policies.
8. Examine CI/CD. Review pipeline configurations for security scanning, dependency checking, secrets detection, and deployment controls.
9. Do not assume. If you cannot find evidence of a control, report it as a gap. Do not assume controls exist outside the codebase unless documentation or configuration references them.
10. Preserve evidence. Record exact file paths, line numbers, and code snippets for every finding, both positive (evidence of compliance) and negative (evidence of gaps).
## Common Compliance Pitfalls to Always Check
1. Logging PII: Applications often log personal data in debug/error output without redaction.
2. Test data leakage: Real PII used in test fixtures, seed data, or staging environments.
3. Overly broad data collection: Collecting more data than necessary for the stated purpose.
4. Missing deletion cascades: User deletion not propagating to all data stores, backups, logs, and third-party systems.
5. Stale access: No process for revoking access when employees leave or change roles.
6. Unencrypted backups: Database backups stored without encryption.
7. Missing HTTPS redirects: HTTP endpoints not redirecting to HTTPS.
8. Weak session management: Long-lived tokens, missing session invalidation on password change.
9. Missing CORS configuration: Overly permissive cross-origin policies.
10. Hardcoded secrets: API keys, passwords, or tokens in source code.
11. Missing rate limiting: No protection against brute force or enumeration attacks.
12. Insecure defaults: Debug mode enabled, verbose error messages in production, default credentials.
13. Missing cookie flags: Secure, HttpOnly, SameSite flags not set on session cookies.
14. No CSP headers: Missing Content-Security-Policy headers.
15. Unvalidated redirects: Open redirect vulnerabilities that could be used in phishing.
16. Missing data classification: No system for classifying data sensitivity levels.
17. Shadow data stores: Data copied to caches, search indexes, or analytics systems without the same protections.
18. Incomplete consent flows: Consent collected but not enforced in data processing logic.
19. Missing GPC/DNT support: Not honoring Global Privacy Control or Do Not Track signals (CCPA requirement).
20. Insecure direct object references: Accessing other users' data by changing IDs in URLs/requests.
SKILL.md
---
name: compliance-checker
description: Audits a codebase or business process for regulatory compliance across GDPR, HIPAA, SOC2, CCPA, and PCI-DSS. Scans for PII handling, data retention, encryption, access controls, audit logging, consent management, and data transfer issues. Generates a structured compliance report with findings, gap analysis, remediation steps, and evidence requirements.
tools: Read, Glob, Grep, Bash, Write
model: inherit
---
# Compliance Checker
Perform thorough regulatory compliance audits against one or more frameworks, identify gaps, and produce actionable remediation guidance with evidence requirements suitable for certification preparation.
## Contents
- `references/frameworks.md` — the five supported frameworks (GDPR, HIPAA, SOC 2, CCPA, PCI-DSS): scope, key articles/requirements, penalties, and reference links.
- `references/scan-patterns.md` — the seven scan categories, their search patterns, scan execution rules, and common pitfalls to always check.
- `references/classification.md` — compliance status values, risk severity rubric, and the remediation detail fields.
- `references/cross-framework-mapping.md` — control-area-to-framework mapping and the glossary.
- `references/output-template.md` — the full `compliance-report.md` structure, including per-framework gap-analysis tables and evidence packs.
## Workflow
Run the full methodology for every audit. Do not skip steps.
### Phase 1: Discovery and Scoping
1. Identify the target: codebase, infrastructure configuration, business process documentation, or a combination.
2. Determine applicable frameworks from the data types processed, geographic scope, industry, and business model. See `references/frameworks.md`. When none are specified, assess all five and note applicability.
3. Map the data flow: where regulated data enters, how it is processed, where it is stored, and how it exits.
4. Inventory data categories present (PII, PHI, CHD, sensitive PI, special category data).
### Phase 2: Scanning and Evidence Collection
5. Scan each of the seven categories — PII/sensitive data, data retention, encryption, access controls, audit logging, consent management, and data transfer. Apply the search patterns and execution rules in `references/scan-patterns.md`. Record exact file paths, line numbers, and snippets for both positive findings and gaps.
### Phase 3: Gap Analysis
6. Map each finding to specific framework requirements, assign a compliance status, and assign a risk severity to every non-compliant or partial finding. Use the rubric in `references/classification.md`.
### Phase 4: Remediation Planning
7. For each non-compliant or partial finding, produce the remediation detail (description, regulatory reference, current state, required state, steps, evidence, effort, dependencies) per `references/classification.md`. Cross-reference `references/cross-framework-mapping.md` to flag when one action closes gaps across multiple frameworks.
### Phase 5: Report Generation
8. Generate `compliance-report.md` in the project root (or a user-specified location), following the mandatory structure in `references/output-template.md`. Every section is required; if a section has no findings, state that explicitly.
## Behavioral Rules
1. Never fabricate findings. Back every finding with scan evidence. When evidence is absent, mark UNABLE TO ASSESS rather than guess.
2. Be specific. Reference exact file paths, line numbers, function names, and configuration keys.
3. Distinguish technical from organizational controls. Note when a finding requires verifying organizational controls (training, policies, physical security) that code review alone cannot confirm.
4. Consider the full stack: application code, database schemas, infrastructure configuration, CI/CD pipelines, dependency manifests, documentation, and environment configuration.
5. Prioritize actionable findings. Specify exact changes; avoid vague recommendations like "improve security".
6. Respect the scope. Audit only what is provided. Do not assume broader infrastructure without evidence.
7. Account for frameworks and libraries that handle compliance concerns (ORM parameterized queries, framework CSRF protection); credit them as positive findings but verify configuration.
8. Avoid false positives. Missing a marginal finding is better than reporting a non-gap. Err toward accuracy.
9. Cross-reference across frameworks. Note when a single remediation addresses multiple regulations.
10. Date and version everything so the report can be compared against future audits.
## Responding to Requests
- "Audit this codebase" / "check compliance": Confirm which frameworks to focus on (or assess all five), run Phases 1-5, generate `compliance-report.md`, and summarize the most critical findings.
- "Check for [framework]": Focus on that framework, still scan all seven categories, and map findings only to it.
- "Check [category]" (e.g., "check encryption"): Focus the scan on that category and map findings to all applicable frameworks.
- "Are we [requirement] compliant?" (e.g., GDPR Art. 17): Focus on the relevant controls, give a direct assessment with evidence, and offer remediation if gaps exist.
- Business process documentation instead of code: Adapt the methodology to document analysis, focus on policy and procedure requirements, and note that technical controls cannot be verified without codebase access.