Skip to content

feat: implement middleware authentication, secure secret redaction, a… - #772

Merged
nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
Alhaji-naira:issue/fixes
Jul 26, 2026
Merged

nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
Alhaji-naira:issue/fixes

Conversation

@Alhaji-naira

Copy link
Copy Markdown
Contributor

Description

This PR addresses critical performance bottlenecks and security vulnerabilities. It improves initial load times by code-splitting heavy chart libraries, stabilizes UI rendering for massive property lists, and enforces secure data handling for both client routing and error reporting.

🚀 Performance Optimizations

  • Deferred Heavy Chart Libraries (Closes [Perf] Defer recharts / d3 charts to dynamic imports above-the-fold #650):

    • Created a reusable withLazyChart HOC combining next/dynamic and IntersectionObserver.
    • Lazy-loaded TransactionAnalytics and MortgageCalculator to prevent recharts and d3 from blocking the main thread eagerly.
    • Removed duplicate inline chart components from TransactionHistory.tsx to ensure proper code-splitting.
  • Virtualized Property Grids (Closes [Perf] Virtualize large Web3 property grids with @tanstack/react-virtual #651):

    • Built a new VirtualizedPropertyGrid component powered by @tanstack/react-virtual.
    • Replaced the eager grid rendering in SearchResults.tsx (which powers the /properties route) with the virtualized version, solving scroll stuttering on lower-end devices.
    • Mapped aria-setsize, aria-posinset, and role="listitem" onto virtual rows to preserve 100% screen reader accessibility.

🔒 Security Enhancements

  • Strict JWT Validation (Closes [Security] Validate JWT/auth-token in middleware.ts (currently only checks cookie existence) #652):

    • Upgraded the auth-token middleware check to perform full cryptographic signature and expiry validation using jose (jwtVerify), closing an authentication bypass vulnerability.
    • Included a 15-second clock tolerance for distributed servers and updated client-side token parsing in useAuth.ts.
    • Added robust unit test coverage in middleware.test.ts.
  • Automated Secret Redaction (Closes [Security] Strip secrets from error-reporting context (privateKey, mnemonic, cookies) #654):

    • Implemented a recursive payload sanitization utility (redactSecrets) in src/utils/secretRedaction.ts leveraging a WeakSet to safely handle circular references.
    • Integrated the redaction layer into sendToAnalytics (src/utils/errorReporting.ts) to strip sensitive keys (jwt, private_key, token, etc.) from contextual error data and stack traces before transmission.

Testing & Validation

  • ✅ Verified complete pipeline health (npm run lint and npm test).
  • ✅ Mocked the @tanstack/react-virtual grid in SearchResults.test.tsx to ensure tests continue to pass gracefully.
  • ✅ Unit tests provided for new middleware authentication boundaries and secret redaction functions.

Reviewer Notes

Please ensure that the AUTH_SECRET environment variable is correctly configured in staging and production, as the strict middleware validation will safely block users if the secret is missing.

…nd optimize performance with lazy-loading components and virtualized grids.
@drips-wave

drips-wave Bot commented Jul 26, 2026

Copy link
Copy Markdown

@Alhaji-naira Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@nanaf6203-bit nanaf6203-bit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nanaf6203-bit
nanaf6203-bit merged commit f499512 into MettaChain:main Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants