# Quant Capital Admin - Project Audit Report

**Date:** November 25, 2025
**Project:** Quant Capital Admin Dashboard
**Version:** 0.1.0
**Auditor:** Claude Code

---

## Executive Summary

The Quant Capital Admin Dashboard is a Next.js 13-based admin panel for managing quantum capital investments, transactions, users, and financial operations. While the project demonstrates solid code organization and comprehensive error handling, it has **critical security vulnerabilities** and significant gaps in testing and type safety that are concerning for a financial application.

**Overall Risk Rating: MEDIUM-HIGH**

---

## 1. Project Overview

| Attribute | Value |
|-----------|-------|
| Framework | Next.js 13.2.4 |
| UI Library | React 18.2.0 + React Bootstrap |
| State Management | React Context API + React Query |
| Authentication | JWT (localStorage) |
| Logging | Winston with daily rotation |
| Port | 4819 (development) |

### Key Features
- Dashboard with investment/profit tracking
- User management and profiles
- Sales person management
- Transaction history with pagination
- Daily ledger management
- Withdrawal approval workflow
- Wise payment integration
- Real-time notifications

---

## 2. Security Audit

### 2.1 Critical Vulnerabilities

#### **HIGH: XSS via dangerouslySetInnerHTML**
- **Location:**
  - `widgets/cards/PricingCard.js` (lines 13, 35)
  - `components/menuscreen/Disclaimers.js` (lines 241, 243)
- **Risk:** Content from API rendered without sanitization can execute malicious scripts
- **Recommendation:** Sanitize HTML content server-side or use DOMPurify

#### **HIGH: Tokens Stored in localStorage**
- **Location:** `utils/tokenManager.js`
- **Risk:** JWT tokens and refresh tokens in localStorage are vulnerable to XSS attacks
- **Recommendation:** Migrate to HttpOnly cookies with server-side token refresh


### 2.2 Medium Vulnerabilities

| Issue | Location | Risk | Recommendation |
|-------|----------|------|----------------|
| No CSRF Protection | `pages/api/apiclient.js` | Form hijacking | Implement CSRF tokens |
| S3 URL Exposed | `next.config.js` | Bucket enumeration | Use signed URLs |


### 2.3 Security Strengths
- JWT-based authentication with token refresh mechanism
- Rate limiting implementation for login, OTP, and transactions
- File upload validation (MIME type, size limits)
- Winston logging with audit trails
- HOC-based route protection (`withAuth.js`)

---

## 3. Code Quality Audit

### 3.1 Testing Coverage

**CRITICAL: Zero Test Coverage**

- No test files found (0 out of 186 JS files)
- No Jest or testing framework configured
- No testing scripts in `package.json`
- No CI/CD test validation

**Risk:** High regression potential, unsafe refactoring, untested critical paths (auth, payments)

### 3.2 TypeScript Adoption

**Status:** JavaScript only (no TypeScript)

- No `tsconfig.json`
- No PropTypes on most components
- No static type checking

**Risk for Financial Application:** HIGH - No type safety for sensitive operations

### 3.3 Code Organization

**Strengths:**
- Clear directory structure (`/pages`, `/utils`, `/hooks`, `/context`, `/components`)
- Separation of concerns (logger, tokenManager, apiClient)
- Custom hooks for reusable logic

**Weaknesses:**
- Inconsistent component locations (4 different directories)
- Large monolithic files:
  - `pages/api/apiclient.js` - 643 lines
  - `context/Context.js` - 428 lines
- 99 `console.*` statements mixed with logger utility

### 3.4 Error Handling

**Strengths:**
- Centralized error constants (`constants/errors.js`)
- Rate limit handling with user-friendly messages
- Axios interceptor for 401 handling
- Error message mapping utility

**Weaknesses:**
- Inconsistent logging (console vs logger utility)
- Some error swallowing without logging
- No global error boundary

---

## 4. Dependency Audit

### 4.1 Outdated Packages

| Package | Current | Latest | Priority |
|---------|---------|--------|----------|
| Next.js | 13.2.4 | 14.x+ | High |
| React | 18.2.0 | 18.3.x | Medium |
| ESLint | 8.37.0 | 9.x | Low |

### 4.2 Redundant Dependencies

- **Date Pickers:** Both `react-datepicker` and `react-date-range` (remove one)
- **Charting:** Both `chart.js` and `apexcharts` (consolidate)

### 4.3 Missing Dev Dependencies

- No testing framework (Jest, Vitest)
- No code formatter (Prettier)
- No pre-commit hooks (husky, lint-staged)
- No TypeScript

### 4.4 Total Dependencies: 50 production, 0 dev

---

## 5. Architecture Assessment

### 5.1 Application Flow

```
Login (index.js)
  → Token Storage (localStorage)
  → Protected Routes (withAuth HOC)
  → API Calls (apiclient.js with interceptors)
  → Dashboard/Users/Transactions
```

### 5.2 State Management

- **Global State:** React Context (`ApiProvider`)
- **Server State:** React Query (partial usage)
- **Local State:** Component useState
- **Auth State:** localStorage + Context

**Issue:** Mixed patterns with no single source of truth

### 5.3 API Integration

- Centralized Axios client with interceptors
- Automatic token refresh on 401
- Request/response logging
- Rate limit detection

---

## 6. Performance Considerations

### 6.1 Positives
- React Query caching (partially utilized)
- Request timing instrumentation
- Next.js code splitting available

### 6.2 Concerns
- Two charting libraries increase bundle size
- localStorage read on every auth check
- Token parsing on every authentication validation
- No visible image optimization

---

## 7. Logging & Monitoring

### 7.1 Implementation
- Winston logger with daily rotation
- 7-day log retention, 20MB file limit
- Separate error and combined logs
- Request duration tracking

### 7.2 Issues
- 99 console statements should use logger
- No production error tracking (Sentry)
- Debug logging disabled in production

---

## 8. Recommendations by Priority

### Immediate (Critical)

1. **Fix XSS Vulnerabilities**
   - Sanitize all `dangerouslySetInnerHTML` content
   - Use DOMPurify or sanitize server-side

2. **Migrate Token Storage**
   - Move from localStorage to HttpOnly cookies
   - Implement server-side token refresh endpoint

3. **Add Server-Side Validation**
   - Validate all form inputs on backend
   - Never trust client-side validation alone

### Short-term (Important)

4. **Add Test Coverage**
   - Start with utility functions and API client
   - Target 80% coverage for critical paths

5. **Adopt TypeScript**
   - Begin with API types and error handling
   - Gradually migrate components

6. **Standardize Logging**
   - Replace all console.* with logger utility
   - Add error tracking service (Sentry)

7. **Update Dependencies**
   - Upgrade Next.js to 14.x
   - Remove redundant libraries

### Long-term (Enhancement)

8. **Refactor Large Files**
   - Split `apiclient.js` into domain-specific modules
   - Extract business logic from `Context.js`

9. **Add Security Headers**
   - Implement CSP, X-Frame-Options, etc.
   - Configure CORS properly

10. **Performance Optimization**
    - Implement route-based code splitting
    - Add image optimization

---

## 9. Key Files Requiring Attention

| File | Lines | Issues |
|------|-------|--------|
| `utils/tokenManager.js` | 190 | localStorage tokens |
| `pages/api/apiclient.js` | 643 | Large file, needs splitting |
| `context/Context.js` | 428 | Mixed concerns |
| `widgets/cards/PricingCard.js` | - | XSS vulnerability |
| `components/menuscreen/Disclaimers.js` | - | XSS vulnerability |
| `pages/components/hoc/withAuth.js` | - | Client-only auth check |

---

## 10. Compliance Considerations

For a financial application, consider:
- **PCI DSS** compliance for payment data
- **GDPR** compliance for user data (if serving EU users)
- **Data encryption** at rest and in transit
- **Audit logging** requirements
- **Access control** documentation

---

## Conclusion

The Quant Capital Admin Dashboard is a functional admin panel with good code organization but has significant security and quality gaps that need immediate attention, especially given its financial nature. The lack of test coverage and TypeScript adoption increases risk for ongoing development. Prioritize the security fixes outlined above before adding new features.

**Next Steps:**
1. Address critical XSS vulnerabilities
2. Implement HttpOnly cookie authentication
3. Add server-side validation
4. Set up testing infrastructure
5. Begin TypeScript migration
