Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Submit feedback
    • Contribute to GitLab
  • Sign in
F
finwise-miniapp-be
  • Project
    • Project
    • Details
    • Activity
    • Releases
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 0
    • Issues 0
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • ThinhNC
  • finwise-miniapp-be
  • Merge Requests
  • !28

Merged
Opened Aug 19, 2026 by ThinhNC@ThinhNC
  • Report abuse
Report abuse

fix(core): complete project audit remediation for auth, financial integrity, and performance

Summary of Changes - Backend

This PR implements comprehensive audit remediations covering financial integrity, authentication hardening, N+1 query elimination, route validation, database indexing, and static analysis cleanup.

Financial Integrity & Security (P0 & P1)

  • Enforced Wallet Balance Immutability: Removed balance from updateWalletSchema and UpdateWalletDto. Wallet balances can now only be mutated via Transaction (Income/Expense) or Transfer operations within serializable transactions.
  • Dual-Channel Token Delivery: Updated /auth/login and /auth/refresh endpoints to return accessToken and refreshToken directly in the JSON response payload alongside HTTP-only cookies to support mobile WebView / Mini App environments.
  • Hardened Access Token Lifecycle: Reduced default JWT accessExpiresIn from 24h to 30m and added active user validation (isActive & deletedAt === null) in authMiddleware backed by a 60-second in-memory/Redis cache.

Performance & Database Optimization (P1 & P2)

  • Eliminated N+1 Aggregate Queries:
    • Added BudgetRepository.getBatchSpendingSummaries to calculate spending across all budgets in a single database query.
    • Optimized NotificationRepository.findBudgetCandidates to batch-fetch transactions across candidate budgets.
  • Added Composite Indexes:
    • Added @@index([userId, isArchived]) on Wallet.
    • Added @@index([status, updatedAt]) on NotificationDelivery.
    • Deployed migration 20260819223000_add_composite_indexes.

API Validation & Code Quality (P2 & P3)

  • UUID Parameter Validation: Added userParamsSchema and sessionParamsSchema to validate :id on admin and session routes, preventing unhandled Prisma P2023 (500) errors.
  • ESLint & Compiler Hygiene: Updated eslint.config.mjs to support _ prefix for intentionally unused variables/caught errors; normalized Express 4-argument error handler signature (_next). Achieved 0 lint errors, 0 warnings.
Edited Aug 19, 2026 by ThinhNC

Check out, review, and merge locally

Step 1. Fetch and check out the branch for this merge request

git fetch origin
git checkout -b fix/be-auth-balance-n1-remediation origin/fix/be-auth-balance-n1-remediation

Step 2. Review the changes locally

Step 3. Merge the branch and fix any conflicts that come up

git fetch origin
git checkout origin/develop
git merge --no-ff fix/be-auth-balance-n1-remediation

Step 4. Push the result of the merge to GitLab

git push origin develop

Note that pushing to GitLab requires write access to this repository.

Tip: You can also checkout merge requests locally by following these guidelines.

  • Discussion 0
  • Commits 1
  • Changes 22
Assignee
No assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
0
Labels
None
Assign labels
  • View project labels
Reference: ThinhNC/finwise-miniapp-be!28

Revert this merge request

This will create a new commit in order to revert the existing changes.

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.

Cherry-pick this merge request

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.