feat: add field-level encryption for PII#102
Merged
Conversation
suesuee
approved these changes
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Developer
Kevin Rutledge
What changed?
Added AES-256-GCM field-level encryption for PII stored in the Referral, EmailSuppression, and SmsConsent tables. Encrypted fields are stored as base64url ciphertext. Lookup tables (EmailSuppression, SmsConsent) use HMAC-SHA256 blind indexes for exact-match queries without decrypting. Also ran npm audit fix to resolve 18 of 19 dependency vulnerabilities.
New files:
src/lib/encryption.ts- encrypt(), decrypt(), blindIndex() using Node.js cryptotest/lib/encryption.test.ts- 13 tests for round-trip, tamper detection, blind index determinismtest/mocks/encryption.ts- shared passthrough mock for service/action/API testsscripts/migrate-encrypt-pii.ts- one-time data migration script for existing rowsModified:
prisma/schema.prisma- widened PII columns to VarChar(512), added emailHash/phoneHash columns, updated indexessrc/services/referral.ts- encrypt on write, decrypt on read for 4 PII fieldssrc/services/email-suppression.ts- blind index lookups, encrypted email storagesrc/env.ts- added FIELD_ENCRYPTION_KEY and BLIND_INDEX_KEY env varsHow to test
openssl rand -hex 32for each of FIELD_ENCRYPTION_KEY and BLIND_INDEX_KEYnpm test- 237 tests pass (14 new encryption tests)npm run build- build succeedsnpx tsc --noEmit- zero type errorsnpm audit- down to 1 low-severity vulnerability (nodemailer, requires breaking major version)Checklist