feat: file upload security, provider schema change detection, preferences versioning, and ML transaction classification - #507
Open
Sundayabel222 wants to merge 4 commits into
Conversation
Implement a file security pipeline that scans uploads for malware, validates file types by magic bytes (beyond extension/MIME claims), holds inconclusive scans in quarantine for a configurable period, and records SHA-256 integrity hashes for tamper detection. The pipeline is wired into the KYC document upload route so infected or spoofed files are rejected before reaching S3, with every outcome persisted in upload_security_records for auditability. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
Capture canonical snapshots of provider API contracts, diff new captures against the last recorded version, and classify each change as breaking or non-breaking (removed required fields, type changes and removed enum values are breaking). Every capture is persisted as a semver-versioned record (MAJOR on breaking, MINOR on additive), and a notification is sent through the structured logger and an optional webhook whenever a tracked contract changes. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
…bhooks Add a monotonic version to user preferences with optimistic concurrency control: stale updates are rejected with the current state so concurrent sessions can't silently overwrite each other. Conflicts can be resolved explicitly (server-wins / client-wins / merge). Every mutation writes an append-only audit trail (preference_change_log) and enqueues a preference.changed webhook into the outbox for at-least-once delivery. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
Add a Naive Bayes transaction type classifier that categorises transactions (deposit/withdraw/payment/payout/refund/fee) with a calibrated confidence score. Includes a training data collection pipeline backed by labelled samples, an online-learning feedback loop for human corrections, batch retraining with persisted model versions, and Prometheus accuracy/confidence monitoring. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
Hey @Sundayabel222! 👋 It looks like this PR isn't linked to any issue. If this PR is for one of the issues assigned to you as part of a Wave, please link it to ensure your contribution is tracked properly. You can do this by adding a keyword to the PR description (e.g.,
|
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.
Overview
This PR implements four independent features across four commits:
1. Antivirus scanning for uploads (
3e19c2e)Problem: Uploads (KYC documents, dispute evidence) are accepted based on extension/MIME claims only; malicious files could be stored without any scanning.
Changes:
FileSecurityService(src/services/fileSecurityService.ts) with a full pipeline:CLAMAV_HOST/CLAMAV_PORTare configured, falling back to an embedded signature scanner (EICAR, executables, dangerous scripts, PDF JavaScript) otherwiseUPLOAD_QUARANTINE_MINUTES, default 24h) with auto-release of expired quarantines and admin approve/reject endpointsupload_security_recordstable + rollback migrationAcceptance criteria:
Env vars:
CLAMAV_HOST,CLAMAV_PORT,CLAMAV_TIMEOUT_MS,UPLOAD_QUARANTINE_MINUTES2. Provider API schema change detection (
1d1167e)Problem: Provider API contracts can change silently and break integrations with no monitoring.
Changes:
ProviderSchemaMonitorService(src/services/providerSchemaMonitorService.ts):PROVIDER_SCHEMA_ALERT_WEBHOOK_URLprovider_api_schema_versionstable + rollback migrationAcceptance criteria:
Env vars:
PROVIDER_SCHEMA_ALERT_WEBHOOK_URL3. User preferences versioning (
e2c52c0)Problem: User preferences had no versioning, so concurrent sessions could silently overwrite each other's changes.
Changes:
UserSettingsnow carries a monotonicversion, incremented on every mutationupdateSettingssupports optimistic concurrency viaexpectedVersion; stale updates return a 409 conflict with the current state instead of clobbering. ExplicitresolveSettingsConflictstrategies:server-wins,client-wins,mergepreference_change_logtable records every update/reset/delete with version transitions and changed fields (PreferenceChangeService)preference.changedevents enqueued into the sharedwebhook_outboxfor at-least-once delivery with retriesexpectedVersion; conflict responses carry the latest settings so clients can re-syncAcceptance criteria:
4. ML transaction type classification (
27ce618)Problem: Transaction types are manually assigned; ML classification can auto-categorise transactions for better reporting.
Changes:
TransactionClassifierService(src/services/transactionClassifierService.ts) — multinomial Naive Bayes classifier with Laplace smoothing over 6 categories (deposit, withdraw, payment, payout, refund, fee), seeded with domain priors so it works before any training datarecordTrainingExamplepersists labelled samples from real transactions (transaction_classifier_training) and folds them into the live modelsubmitHumanFeedbackstores corrections (transaction_classifier_feedback) and applies them to the model immediately via online learning;trainModelperforms batch retraining and persists versioned model snapshotsgetClassificationAccuracyevaluates against human-labelled samples and exports Prometheus metrics (accuracy gauge, per-category counters, confidence histogram, feedback/training-sample counts)transaction_classifier_training/transaction_classifier_feedback/transaction_classifier_modelstables + rollback migrationAcceptance criteria:
Testing
main(remaining failures are pre-existing environment issues — missing nativesharpbinary, no live Postgres/Redis)tsc --noEmit: no new type errors (20 pre-existing errors insrc/stellar/sep02.tsunchanged)anywarnings)Migrations
4 new migrations (all with rollback files):
20260825_create_upload_security_records(.down).sql20260825_create_provider_api_schema_versions(.down).sql20260825_create_preference_change_log(.down).sql20260825_create_transaction_classifier_tables(.down).sqlRun with
npm run migrate:up.