9.5 KiB
9.5 KiB
Phase 3.1 — Human Review Preparation and Master Backlog Critique
- Review Phase: Phase 3.1 — Human Review Preparation and Master Backlog Critique
- Repository HEAD:
715873b2ecc3a72ba974bb2a2be87c5ba82bd4e7 - Execution Mode:
REVIEW_ONLY_NO_CODE_MUTATION - Canonical Verified Findings Source:
docs/audit/20-verified-findings-index.json - Original Task Count: 10 (9 Implementation + 1 Verification)
- Final Task Count: 10 (9 Implementation + 1 Verification)
- Tasks Modified / Refined: 6 (
TASK-AUTH-001,TASK-FIN-001,TASK-FE-001,TASK-VERIFY-001,TASK-SEC-001,TASK-SEC-002) - Business Decisions Reclassified: 3 (
DECISION-001,DECISION-002,DECISION-003)
1. Executive Assessment
A rigorous, engineering-grade review of the Phase 3 Master Task Backlog was conducted against the actual repository source code in backend/ and src/. The review confirmed that all 14 verified findings are valid, but identified 5 critical technical refinements required before human approval:
- Authentication Token Storage Architecture (
TASK-AUTH-001): Storing JWT access tokens inlocalStorageexposes the storefront to Cross-Site Scripting (XSS) token exfiltration. The recommended architecture has been revised to use in-memory token state in Zustand / Axios interceptors with optional HttpOnly cookie support for production environments. - Financial Task Scope Cleanup (
TASK-FIN-001): Inventory availability checking was removed fromTASK-FIN-001as scope creep, because the PrismaProductschema (schema.prisma) does not contain an inventory/stock column. The task is strictly focused on arbitrary-precisionDecimalarithmetic (BE-001) and batchedfindManyproduct lookups (BE-002). - Business Decision Classification (
DECISION-002): Payment gateway provider selection (DECISION-002) was removed from the canonical remediation backlog because no verified finding or active task requires payment gateway implementation. It is reclassified asFUTURE_SCOPE. - Declarative Routing Justification (
TASK-FE-001): Confirmed viasrc/App.tsxevidence that manualuseState("home")view rendering causes direct link URL navigation failure and state desynchronization. React Router DOM (react-router-dom) is explicitly justified and detailed with an exact route table. - Behavior-Oriented E2E Acceptance Criteria (
TASK-VERIFY-001): Generic criteria ("100% of tests pass") have been replaced with precise, behavior-oriented verification assertions across Authentication, Security, Financial, Quality, and Frontend domains.
2. Findings That Require No Change
The following 8 findings were verified to have clean, accurate root-cause mappings and task assignments requiring no structural change:
SEC-003-> Plaintext OTP disclosure in API payload (Handled inTASK-SEC-002).ADM-001-> Missing RBAC guard on settings API (Handled inTASK-SEC-003).BE-001-> Floating-point monetary calculation error (Handled inTASK-FIN-001).BE-002-> Synchronous N+1 query lookup in order processing (Handled inTASK-FIN-001).TS-002-> Missingslugfield in Prisma seed script (Handled inTASK-BUILD-001).TS-003-> Non-type-onlyResponseimport underisolatedModules(Handled inTASK-BUILD-001).TEST-001-> Stale spec assertions for controller return types (Handled inTASK-BUILD-001).DOC-001-> Static Swagger specification desynchronization (Handled inTASK-DOC-001).
3. Findings Requiring Task Refinements
ARCH-001: Refined token storage mechanism inTASK-AUTH-001. Instead of suggestinglocalStorageas a primary storage target, the task explicitly warns againstlocalStoragedue to XSS vulnerability and specifies in-memory token state + HttpOnly cookie evaluation.SEC-001: Refined threat model and startup failure behavior inTASK-SEC-001to enforce mandatory length checks (minimum 32 bytes) and immediate process exit (process.exit(1)) on missing secrets.SEC-002: ExpandedTASK-SEC-002to explicitly specify rate-limiting and expiration boundaries for SMS OTP codes.FE-001&TS-001: Explicitly mapped storefront route parameters and sub-view interface types inTASK-FE-001.
4. Tasks Requiring Splitting
- Evaluation: No tasks required physical splitting.
TASK-FIN-001was originally considered for splitting, but since inventory checking was identified as unevidenced scope creep and removed, keepingDecimalcalculation (BE-001) and query batching (BE-002) together inTASK-FIN-001is optimal because both operate insideOrdersService.createinbackend/src/orders/orders.service.ts.
5. Tasks Requiring Merging
- Evaluation: The current 9 implementation tasks represent the minimal, non-overlapping task set. No further merging is required.
6. Unsupported Assumptions Identified
- Assumption in
TASK-AUTH-001: AssumedlocalStoragewas the standard production auth token storage mechanism.- Correction:
localStorageis vulnerable to XSS token theft. Revised to specify in-memory Zustand token state with Bearer header interceptor insrc/services/api.ts, with architectural guidance for HttpOnly cookies.
- Correction:
- Assumption in
TASK-FIN-001: AssumedOrdersService.createneeded inventory stock deduction checks.- Correction: Inspection of
backend/prisma/schema.prismashowsProducthas nostockorinventoryfield. Inventory deduction claims removed to prevent scope creep.
- Correction: Inspection of
7. Scope Creep Identified and Removed
- Removed Item: Inventory availability checking and stock deduction in
TASK-FIN-001. - Removed Item: Payment Gateway Provider Selection (
DECISION-002) from active remediation backlog. Moved toFUTURE_SCOPE.
8. Security Deep-Dive Review
TASK-SEC-001(JWT Secret Enforcement):- Threat Model: Attackers forging JWT signatures with role
Adminor arbitrarysub(userId) whenJWT_SECRETfalls back to'super-secret-key-canina'. - Failure Behavior: Server startup terminates immediately (
process.exit(1)) withFATAL: JWT_SECRET environment variable is missing or insecure.
- Threat Model: Attackers forging JWT signatures with role
TASK-SEC-002(CSPRNG OTP & Payload Sanitization):- Threat Model: PRNG state prediction of
Math.random()to guess 5-digit OTPs; exploitation of plaintextcodereturned in API JSON response. - Remediation: Use
crypto.randomInt(10000, 100000). Stripcodekey from response. Enforce 2-minute OTP expiry in Redis/memory.
- Threat Model: PRNG state prediction of
TASK-SEC-003(Admin Settings RBAC Enforcement):- Threat Model: Authenticated
User_PetOwnerclients sending requests to/api/settingsto overwrite site branding or scientific terms. - Remediation: Apply
@UseGuards(JwtAuthGuard, RolesGuard)and@Roles('Admin')onSettingsController.
- Threat Model: Authenticated
9. Architecture Review
- Frontend Routing (
TASK-FE-001):src/App.tsxevidence shows manualuseState<View>("home")and custompopstatelisteners. Direct page loads to/shopor/profilerevert to home page.- Solution: Integrate
react-router-domwith<BrowserRouter>and explicit route map:/,/shop,/product/:id,/wiki,/profile/*,/checkout,/order-success,/order-tracking.
- Backend API Client Integration (
TASK-AUTH-001):- Storefront
src/services/authService.tscurrently has partialsendOtpandverifyOtpmethods. WiringuserStoreto update in-memory state on successfulverifyOtpcompletes the protocol alignment.
- Storefront
10. Dependency & Wave Adjustments
The execution waves have been refined to prioritize unblocking CI early:
- Wave 0 — Security & Financial Core (P0):
TASK-SEC-001,TASK-SEC-002,TASK-SEC-003,TASK-FIN-001. - Wave 1 — Build Health & Spec Alignment (P1):
TASK-BUILD-001(Unblocks CI Pipeline!). - Wave 2 — Auth Protocol & Storefront Integration (P1):
TASK-AUTH-001(Depends onTASK-SEC-002). - Wave 3 — Frontend Routing & CI Pipeline (P2):
TASK-FE-001,TASK-DEVOPS-001(TASK-DEVOPS-001depends onTASK-BUILD-001). - Wave 4 — Documentation & Behavior Verification (P3 / Verification):
TASK-DOC-001,TASK-VERIFY-001.
11. Acceptance Criteria Refinements
All generic acceptance criteria were replaced with concrete, observable, testable assertions.
Example (TASK-FIN-001):
- Old: "Order total is accurate."
- New: "
OrdersService.createaccumulates subtotals usingDecimal.add()without primitive JS number conversion; unit spec asserts19.99 * 3 + 5.01 = 65.00with 0 decimal rounding artifacts;this.prisma.product.findManyis called exactly once per checkout request."
12. Business and Product Decision Classification
| Decision ID | Title | Category | Description | Status |
|---|---|---|---|---|
| DECISION-001 | SMS Gateway Provider Selection | PRODUCT_DECISION |
Production SMS Gateway selection (e.g. Kavenegar, FarazSMS, Twilio) for NestJS AuthService.sendOtp. Dev mode uses stdout logger. |
PENDING_PRODUCT_INPUT |
| DECISION-002 | Live Payment Gateway Provider Selection | FUTURE_SCOPE |
Merchant payment gateway provider selection for wallet deposits. Unrelated to current audit findings. | FUTURE_SCOPE |
| DECISION-003 | Storefront vs Admin Architecture | PRODUCT_DECISION |
Decision whether Admin UI remains embedded in SPA (/admin/*) or isolated into a standalone admin portal repo. |
PENDING_PRODUCT_INPUT |
13. Final Recommended Backlog Summary
- Total Tasks: 10 (9 Implementation + 1 Verification)
- Status: 100% READY FOR HUMAN APPROVAL