fix: resolve security issues #800 #803 #804 #806#946
Open
JudeDaniel6 wants to merge 1 commit into
Open
Conversation
…rinafcode#806 rinafcode#800 - EncryptionService: replace SHA-256 with scrypt KDF - Use crypto.scryptSync(secret, salt, 32) for AES-256 key derivation - Require ENCRYPTION_SALT env var at startup (fails fast if missing) - Add ENCRYPTION_SALT to .env.example with generation instructions - Add unit tests verifying scrypt is used (not SHA-256) rinafcode#803 - AuthService logout: blacklist the current access token - Add jti claim to access token payload in generateTokens() - Update logout(userId, accessToken?) to decode and blacklist the JTI with TTL equal to remaining token lifetime - Update AuthController.logout to extract Bearer token and pass it - Add tests covering JTI blacklisting and graceful fallback rinafcode#804 - GDPR erasure: cascade-delete financial records and active sessions - Wrap erasure in a TypeORM DataSource transaction - Anonymize payments, enrollments, audit_logs, notifications inside tx - Revoke active sessions before transaction (fast path) - Update GdprModule to import TypeOrmModule (provides DataSource) - Add tests: cascade anonymization, NotFoundException, idempotency rinafcode#806 - FraudDetectionService: configurable thresholds + behavioral signals - Introduce FraudSignalProvider interface for pluggable signal sources - IpRateSignalProvider, NewDeviceSignalProvider, LargeTransactionSignalProvider - VelocitySignalProvider: flag users exceeding N purchases/hour - GeoAnomalySignalProvider: flag purchase country != registration country - All thresholds configurable via ConfigService env vars (FRAUD_*) - Unit tests for each provider independently + aggregate service Closes rinafcode#800, Closes rinafcode#803, Closes rinafcode#804, Closes rinafcode#806
Contributor
|
kindly resolve conflict |
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.
Summary
Resolves all four open security issues assigned to @JudeDaniel6.
#800 — EncryptionService uses SHA-256 instead of a proper KDF
Problem: Key derivation via
crypto.createHash('sha256')has no work factor, making brute-force trivial.Fix:
crypto.scryptSync(secret, salt, 32, { N: 16384, r: 8, p: 1 })ENCRYPTION_SALTenv var (startup fails fast if absent)#803 — AuthService logout does not blacklist the current access token
Problem:
logout()only nulls the refresh token; the access token stays valid until natural expiry.Fix:
jticlaim to access token ingenerateTokens()logout(userId, accessToken?)to decode the token, extractjti, and calltokenBlacklistService.addToBlacklist(jti, remainingTtlMs)AuthController.logoutto extract the Bearer token and pass it to the service#804 — GDPR erasure does not cascade-delete financial records and active sessions
Problem:
eraseUserData()only nulls profile fields, leaving orphaned payments/enrollments/audit logs and usable sessions.Fix:
DataSource.transaction()payments,enrollment,audit_logs, andnotificationstables inside the transactionGdprModuleupdated to importTypeOrmModule(providesDataSource)#806 — FraudDetectionService has hardcoded thresholds and no behavioral signals
Problem: Three hardcoded threshold checks are trivially bypassed; no velocity or geo signals.
Fix:
FraudSignalProviderinterface for pluggable signal sourcesIpRateSignalProvider,NewDeviceSignalProvider,LargeTransactionSignalProvider— existing logic, now configurable viaConfigServiceVelocitySignalProvider— flags users exceedingFRAUD_MAX_PURCHASES_PER_HOUR(configurable)GeoAnomalySignalProvider— flags when purchase country differs from registration countryFRAUD_IP_RATE_THRESHOLD,FRAUD_NEW_DEVICE_AMOUNT_THRESHOLD,FRAUD_LARGE_TX_THRESHOLD,FRAUD_MAX_PURCHASES_PER_HOUR)Testing
All 4 target test suites pass (37 new/updated tests):
encryption.service.spec.ts— 6 tests ✅auth.service.spec.ts— 10 tests ✅gdpr.service.spec.ts— 5 tests ✅fraud-detection.service.spec.ts— 16 tests ✅Closes #800
Closes #803
Closes #804
Closes #806