@softspark/ai-toolkit 1.4.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,303 @@
1
+ # HIPAA Rules Reference
2
+
3
+ Technical controls mapping for the HIPAA Security Rule, Privacy Rule, and Breach Notification Rule. Used by the `hipaa-validate` skill to cite specific regulatory sections in findings.
4
+
5
+ ## Enforcement — 45 CFR Part 160, §160.404
6
+
7
+ The enforcement rule establishes civil money penalty tiers for HIPAA violations. Understanding penalty exposure helps teams prioritize remediation.
8
+
9
+ ### Penalty Tiers (§160.404(b)(2))
10
+
11
+ | Tier | Knowledge Level | Per Violation | Annual Maximum |
12
+ |------|----------------|---------------|----------------|
13
+ | 1 | Did not know (and reasonable diligence would not have revealed) | $100 – $50,000 | $1,500,000 |
14
+ | 2 | Reasonable cause, not willful neglect | $1,000 – $50,000 | $1,500,000 |
15
+ | 3 | Willful neglect, corrected within 30 days | $10,000 – $50,000 | $1,500,000 |
16
+ | 4 | Willful neglect, not timely corrected | $50,000 minimum | $1,500,000 |
17
+
18
+ **How this maps to scan findings**:
19
+ - HIGH findings with `definitive` confidence (Categories 1, 3, 4, 7, 8) typically represent Tier 2-3 exposure — the organization "should have known" via reasonable diligence
20
+ - Unresolved findings after notification represent potential Tier 3-4 exposure
21
+ - Heuristic findings (Categories 2, 5, 6) require investigation before tier assessment
22
+
23
+ ### Statute of Limitations (§160.414)
24
+
25
+ Actions must be commenced within **6 years** from the date of occurrence. Continuing violations accrue a separate violation each day (§160.406).
26
+
27
+ ## Security Rule — 45 CFR §164.302-318
28
+
29
+ The Security Rule establishes national standards for protecting electronic Protected Health Information (ePHI).
30
+
31
+ ### §164.306 — General Rules (Flexibility of Approach)
32
+
33
+ **Requirement**: Covered entities must assess potential risks and vulnerabilities and implement security measures sufficient to reduce risks to a reasonable and appropriate level. The rule allows flexibility — entities may use any security measures that allow them to reasonably and appropriately implement the standards.
34
+
35
+ **Why this matters for scanning**:
36
+ - Heuristic findings (Categories 2, 5, 6) flag *potential* gaps — organizations may satisfy the requirement through alternative means not detectable by file-level co-occurrence checks
37
+ - The standard is "reasonable and appropriate" — not prescriptive technology mandates
38
+ - Entity size, complexity, and capabilities should be factored when assessing findings
39
+
40
+ **Detectable by**: Not directly scanned. Referenced in heuristic confidence disclaimers to prevent over-weighting.
41
+
42
+ ### §164.308 — Administrative Safeguards
43
+
44
+ **Requirement**: Administrative actions, policies, and procedures to manage the selection, development, implementation, and maintenance of security measures to protect ePHI.
45
+
46
+ This is the most frequently cited section in HIPAA enforcement actions. While primarily policy-driven, several subsections have code-detectable implications.
47
+
48
+ #### §164.308(a)(1)(i) — Security Management Process
49
+
50
+ Implement policies to prevent, detect, contain, and correct security violations. Includes risk analysis and risk management.
51
+
52
+ **Code implications**:
53
+ - Security scanning should be part of CI/CD pipeline
54
+ - Risk assessment documentation should exist for PHI-handling systems
55
+ - Vulnerability management process for dependencies
56
+
57
+ **Detectable by**: Not directly scanned. Presence of security policy docs (`SECURITY.md`, `security-policy.*`) may be checked in compliance mode.
58
+
59
+ #### §164.308(a)(3) — Workforce Security
60
+
61
+ Implement policies to ensure workforce members have appropriate access to ePHI and prevent unauthorized access.
62
+
63
+ **Code implications**:
64
+ - Role-based access control (RBAC) implementation
65
+ - Principle of least privilege in permission models
66
+ - Access termination procedures when workforce members leave
67
+
68
+ **Detectable by**: Category 5 (Access Control Gaps — partial). Auth keyword checks detect missing access control but cannot verify least-privilege enforcement.
69
+
70
+ #### §164.308(a)(5) — Security Awareness and Training
71
+
72
+ Implement a security awareness and training program for all workforce members.
73
+
74
+ **Code implications**:
75
+ - Not directly code-scannable
76
+ - Security documentation and onboarding materials should reference PHI handling procedures
77
+
78
+ **Detectable by**: Not directly scanned. Informational reference.
79
+
80
+ #### §164.308(a)(6) — Security Incident Procedures
81
+
82
+ Implement policies and procedures to address security incidents. Includes identifying, responding to, mitigating, and documenting incidents.
83
+
84
+ **Code implications**:
85
+ - Incident response runbooks should exist
86
+ - Security event monitoring and alerting should be configured
87
+ - Incident logging should be separate from application logging
88
+
89
+ **Detectable by**: Not directly scanned. Compliance officers should verify incident response documentation exists.
90
+
91
+ #### §164.308(b)(1) — Business Associate Contracts
92
+
93
+ Covered entities must obtain satisfactory assurances from business associates that they will appropriately safeguard ePHI, implemented through BAA contracts.
94
+
95
+ **Code implications**:
96
+ - Every third-party service that receives, creates, maintains, or transmits PHI requires a BAA
97
+ - This includes cloud providers, analytics services, email services, database providers, CDN services, message queues, and observability platforms
98
+
99
+ **Detectable by**: Category 6 (Missing BAA References)
100
+
101
+ ### §164.310 — Physical Safeguards
102
+
103
+ **Requirement**: Physical measures, policies, and procedures to protect electronic information systems and related buildings and equipment from natural and environmental hazards and unauthorized intrusion.
104
+
105
+ While primarily about physical security, several subsections have code implications.
106
+
107
+ #### §164.310(d)(2)(iii) — Device and Media Controls: Disposal
108
+
109
+ **Requirement**: Implement procedures for removal of ePHI from electronic media before the media are made available for re-use.
110
+
111
+ **Code implications**:
112
+ - Temporary files containing PHI must be securely deleted after use
113
+ - Cache files with PHI must be purged on schedule
114
+ - Application teardown/cleanup must not leave PHI artifacts on disk
115
+ - Database exports and backups must follow secure disposal procedures
116
+
117
+ **Detectable by**: Category 8 (PHI Temp File Exposure)
118
+
119
+ #### §164.310(d)(2)(iv) — Device and Media Controls: Data Backup and Storage
120
+
121
+ **Requirement**: Create a retrievable, exact copy of ePHI when needed, before movement of equipment.
122
+
123
+ **Code implications**:
124
+ - Backup procedures for PHI data stores
125
+ - Not directly code-scannable — operational procedure
126
+
127
+ **Detectable by**: Not directly scanned. Informational reference.
128
+
129
+ ### §164.312(a)(1) — Access Control
130
+
131
+ **Requirement**: Implement technical policies and procedures that allow only authorized persons to access ePHI.
132
+
133
+ **Technical controls**:
134
+ - Authentication middleware on all PHI-serving routes
135
+ - Role-Based Access Control (RBAC) or Attribute-Based Access Control (ABAC)
136
+ - Session management with appropriate timeouts
137
+ - No wildcard CORS (`Access-Control-Allow-Origin: *`) on PHI endpoints
138
+ - No `public`, `noAuth`, or `anonymous` route decorators on PHI endpoints
139
+
140
+ **Detectable by**: Category 5 (Access Control Gaps)
141
+
142
+ ### §164.312(a)(2)(iv) — Encryption and Decryption (Access Control Implementation)
143
+
144
+ **Requirement**: Implement a mechanism to encrypt and decrypt ePHI.
145
+
146
+ **Technical controls**:
147
+ - Encryption at rest for all PHI data stores (database-level or application-level encryption)
148
+ - Encrypted file storage for PHI documents
149
+ - No plaintext PHI in browser `localStorage` or `sessionStorage`
150
+ - No plaintext PHI in mobile local storage (`SharedPreferences`, `UserDefaults`) without encryption layer
151
+ - Encryption keys managed via KMS, not hardcoded
152
+ - `encrypt: false` explicitly disabling encryption in database configs
153
+
154
+ **Detectable by**: Category 7 (Encryption at Rest)
155
+
156
+ ### §164.312(b) — Audit Controls
157
+
158
+ **Requirement**: Implement hardware, software, and/or procedural mechanisms to record and examine access and other activity in information systems that contain or use ePHI.
159
+
160
+ **Technical controls**:
161
+ - AuditEvent / audit log creation on every PHI read, write, update, delete
162
+ - Audit trail for administrative operations (user management, permission changes)
163
+ - Audit logging for bulk data exports and batch operations
164
+ - Log retention policies (minimum 6 years per §164.530(j))
165
+ - Tamper-evident audit storage (append-only, separate from application data)
166
+
167
+ **Detectable by**: Category 2 (Missing Audit Logging)
168
+
169
+ ### §164.312(c)(1) — Integrity Controls
170
+
171
+ **Requirement**: Implement policies and procedures to protect ePHI from improper alteration or destruction.
172
+
173
+ **Technical controls**:
174
+ - Input validation and sanitization on PHI fields
175
+ - Data integrity checksums for stored PHI
176
+ - Database constraints (NOT NULL, CHECK, foreign keys) on PHI tables
177
+ - Version control / soft-delete for PHI records
178
+ - Optimistic concurrency control for PHI updates
179
+
180
+ **Detectable by**: Partially detectable — `DELETE FROM.*patient` without soft-delete pattern, missing input validation on PHI route handlers. Full coverage planned for future category.
181
+
182
+ ### §164.312(d) — Person or Entity Authentication
183
+
184
+ **Requirement**: Implement procedures to verify that a person or entity seeking access to ePHI is who they claim to be.
185
+
186
+ **Technical controls**:
187
+ - Multi-factor authentication (MFA) for PHI access
188
+ - Strong password policies
189
+ - Token-based authentication (JWT, OAuth2) with appropriate expiration
190
+ - Session invalidation on logout
191
+ - Failed login attempt limiting
192
+
193
+ **Detectable by**: Category 5 (Access Control Gaps — partial)
194
+
195
+ ### §164.312(e)(1) — Transmission Security
196
+
197
+ **Requirement**: Implement technical security measures to guard against unauthorized access to ePHI being transmitted over an electronic communications network.
198
+
199
+ **Technical controls**:
200
+ - TLS 1.2+ for all API calls transmitting PHI
201
+ - HTTPS (never HTTP) for PHI endpoints
202
+ - `wss://` (never `ws://`) for WebSocket connections carrying PHI
203
+ - TLS-enabled database connections (`ssl: true`, `sslmode: require`)
204
+ - TLS for email transport when PHI is included
205
+ - `rejectUnauthorized: true` (never `false`) for TLS certificate verification
206
+
207
+ **Detectable by**: Category 3 (Unencrypted PHI Transmission)
208
+
209
+ ### §164.314(a) — Organizational Requirements: Business Associate Contracts
210
+
211
+ **Requirement**: A covered entity may permit a business associate to create, receive, maintain, or transmit ePHI on its behalf only if the covered entity obtains satisfactory assurances, in the form of a written contract (BAA), that the business associate will appropriately safeguard the information.
212
+
213
+ **Scope of BAA requirement** (per §164.314(a)(2)(i)):
214
+ - Every subcontractor that creates, receives, maintains, or transmits PHI
215
+ - Cloud infrastructure providers (AWS, GCP, Azure) storing PHI
216
+ - Database-as-a-service providers (MongoDB Atlas, RDS, Firestore)
217
+ - Message queue / event services handling PHI events
218
+ - CDN services delivering PHI content
219
+ - Email / SMS services transmitting PHI notifications
220
+ - Observability platforms receiving PHI in logs or traces
221
+ - Analytics services if any PHI flows to them
222
+
223
+ **Detectable by**: Category 6 (Missing BAA References — BAA Verification Checklist)
224
+
225
+ ### §164.316 — Policies and Procedures and Documentation Requirements
226
+
227
+ **Requirement**: Implement reasonable and appropriate policies and procedures to comply with the Security Rule standards and implementation specifications. Maintain written (which may be electronic) documentation of policies and procedures. Retain documentation for **6 years** from the date of its creation or the date when it last was in effect, whichever is later.
228
+
229
+ **Code implications**:
230
+ - Security policies should be documented and version-controlled
231
+ - Policy documents (`SECURITY.md`, `HIPAA.md`, `security-policy.*`, `hipaa-policy.*`) should exist in the project
232
+ - Audit log retention must be configured for minimum 6 years
233
+ - Changes to security configurations should be tracked in version control
234
+ - Documentation must be available to persons responsible for implementing the procedures
235
+
236
+ **Detectable by**: Compliance mode — check for presence of security policy documents in project root. Informational for developer mode.
237
+
238
+ ## Privacy Rule — 45 CFR §164.502, §164.514, §164.530
239
+
240
+ The Privacy Rule establishes standards for the use and disclosure of PHI. While primarily administrative, several provisions have direct code implications.
241
+
242
+ ### §164.502(b) — Minimum Necessary Standard
243
+
244
+ **Requirement**: When using or disclosing PHI, a covered entity or business associate must make reasonable efforts to limit PHI to the minimum necessary to accomplish the intended purpose of the use, disclosure, or request.
245
+
246
+ **Code implications**:
247
+ - API responses should return only required PHI fields, not entire patient objects
248
+ - Log output must not contain PHI unless explicitly needed for debugging (and then only via safe logging)
249
+ - Database queries should SELECT specific columns, not `SELECT *` on PHI tables
250
+ - Data exports should filter to requested fields only
251
+ - Full-object serialization (`JSON.stringify(patient)`, `json.dumps(patient)`) in responses or logs violates minimum necessary
252
+
253
+ **Detectable by**: Category 1 (PHI in Logs — detects full-object serialization and PHI keyword patterns; also detects SELECT * and full-object API responses)
254
+
255
+ ### §164.514 — De-identification
256
+
257
+ **Requirement**: PHI can be de-identified via Safe Harbor method (removing all 18 identifiers) or Expert Determination method.
258
+
259
+ **Code implications**:
260
+ - No hardcoded real patient data in source code, seed files, or fixtures
261
+ - Test data must use synthetic generators, not real patient records
262
+ - Analytics and reporting pipelines must de-identify before transmission to third parties
263
+ - The 18 HIPAA identifiers define what constitutes PHI — see [phi-identifiers.md](phi-identifiers.md)
264
+
265
+ **Detectable by**: Category 4 (Hardcoded PHI/Test Data)
266
+
267
+ ### §164.530(j)(2) — Documentation and Record Retention
268
+
269
+ **Requirement**: Retain required documentation for 6 years from the date of its creation or the date when it was last in effect, whichever is later.
270
+
271
+ **Code implications**:
272
+ - Audit log retention policies must be configured for minimum 6-year retention
273
+ - PHI-related documentation (BAAs, policies) must be version-controlled
274
+ - Log rotation must not delete audit records prematurely
275
+
276
+ **Detectable by**: Not directly scanned. Informational reference for audit logging findings.
277
+
278
+ ## Breach Notification Rule — 45 CFR §164.408-414
279
+
280
+ The Breach Notification Rule requires covered entities and business associates to notify affected individuals, HHS, and (in some cases) media following a breach of unsecured PHI.
281
+
282
+ ### §164.408-410 — Notification Requirements
283
+
284
+ **Requirement**: Following discovery of a breach of unsecured PHI:
285
+ - Individual notification within 60 days of discovery
286
+ - HHS notification (annually if < 500 affected; within 60 days if ≥ 500)
287
+ - Media notification if ≥ 500 individuals in a single state/jurisdiction
288
+
289
+ ### §164.412 — Law Enforcement Delay
290
+
291
+ **Requirement**: Notification may be delayed if law enforcement determines it would impede a criminal investigation.
292
+
293
+ ### §164.414 — Administrative Requirements
294
+
295
+ **Requirement**: Maintain documentation of breach investigations, risk assessments, and notifications for 6 years.
296
+
297
+ **Code implications**:
298
+ - Not directly code-scannable, but included for awareness
299
+ - PHI exposure findings from this skill represent *potential* breach vectors
300
+ - Teams should understand that unresolved HIGH findings could lead to breach notification obligations if exploited
301
+ - Encryption of PHI at rest and in transit is the primary defense — "unsecured PHI" means unencrypted PHI
302
+
303
+ > **Note**: This rule is not scanned programmatically. It is referenced here so development teams understand the downstream consequences of PHI exposure findings detected by other categories.
@@ -0,0 +1,45 @@
1
+ # HIPAA PHI Identifiers
2
+
3
+ The 18 identifiers defined by HIPAA's Safe Harbor de-identification method (45 CFR §164.514(b)(2)). Removing all 18 from a dataset renders it de-identified under Safe Harbor.
4
+
5
+ Used by the `hipaa-validate` skill (Category 4) to detect hardcoded PHI in source code.
6
+
7
+ ## Identifier Reference
8
+
9
+ | # | Identifier | Detectable | Detection Pattern | Notes |
10
+ |---|-----------|------------|-------------------|-------|
11
+ | 1 | Names | Partial | Co-occurrence of name-like strings (`firstName`, `lastName`, `patientName`) near healthcare keywords | Cannot detect arbitrary proper names; detects field names referencing patient names |
12
+ | 2 | Geographic data (smaller than state) | Partial | `\b\d{5}(-\d{4})?\b` near `zip\|postal\|address\|zipCode\|zip_code` keywords in PHI-adjacent files | Detects ZIP codes near address-related keywords; cannot detect arbitrary city/street names. Context-gated to reduce false positives |
13
+ | 3 | Dates (except year) | Partial | `\b(dob\|dateOfBirth\|birthDate\|birth_date\|date_of_birth)\b` near assignment/value | Detects date-of-birth field references; cannot distinguish real vs. synthetic dates |
14
+ | 4 | Phone numbers | Yes | `\d{3}[\s.-]?\d{3}[\s.-]?\d{4}` near `phone\|tel\|mobile\|cell\|contact` keywords | Context-gated to PHI-adjacent files to reduce false positives |
15
+ | 5 | Fax numbers | Partial | Same pattern as phone, near `fax` keyword | Rarely seen in modern code |
16
+ | 6 | Email addresses | Yes | `[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}` in PHI-adjacent files | High false-positive rate without context gating |
17
+ | 7 | Social Security Numbers | Yes | `\d{3}-\d{2}-\d{4}` in PHI-adjacent files | Primary detection target. Context gate critical — pattern matches version strings and dates |
18
+ | 8 | Medical Record Numbers | Yes | `\b(mrn\|medical.record.number\|medicalRecordNumber\|medical_record)\b` near alphanumeric values | Detects MRN field references and assignments |
19
+ | 9 | Health plan beneficiary numbers | No | — | Plan-specific formats vary. Manual review required |
20
+ | 10 | Account numbers | No | — | Too generic to detect without healthcare context. Manual review required |
21
+ | 11 | Certificate/license numbers | No | — | State-specific formats. Manual review required |
22
+ | 12 | Vehicle identifiers (VIN, plates) | No | — | Not typically in healthcare code. Manual review required |
23
+ | 13 | Device identifiers (UDI, serial numbers) | No | — | Medical device context required. Manual review required |
24
+ | 14 | Web URLs | No | — | Too common in code. Manual review required for patient-specific URLs |
25
+ | 15 | IP addresses | Yes | `\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b` in PHI-adjacent files, excluding `127.0.0.1`, `0.0.0.0`, `localhost` | Context-gated; only flagged in healthcare files |
26
+ | 16 | Biometric identifiers | No | — | Fingerprints, voiceprints, retinal scans. Manual review required |
27
+ | 17 | Full-face photographs | No | — | Image content analysis out of scope. Manual review required |
28
+ | 18 | Any other unique identifying number | No | — | Catch-all category. Manual review required |
29
+
30
+ ## Detection Summary
31
+
32
+ | Category | Count | Detection Method |
33
+ |----------|-------|-----------------|
34
+ | Detectable by regex | 7 | SSN, phone, email, IP, MRN, DOB, ZIP code patterns with context gating |
35
+ | Policy-only (manual review) | 11 | Listed for awareness — no automated detection possible |
36
+
37
+ ## Usage in hipaa-validate
38
+
39
+ Category 4 (Hardcoded PHI/Test Data) applies these patterns only to files identified as PHI-adjacent by the Step 0 context gate. This two-phase approach prevents false positives from:
40
+ - Email addresses in user authentication code
41
+ - IP addresses in infrastructure/networking code
42
+ - Phone number patterns in non-healthcare validation logic
43
+ - SSN-like patterns in version strings or date formats
44
+
45
+ Test directories (`test/`, `tests/`, `__tests__/`, `spec/`, `fixtures/`, `mocks/`) are automatically excluded since test fixtures legitimately contain synthetic PHI data.