Skip to content

Latest commit

 

History

History
462 lines (334 loc) · 13 KB

File metadata and controls

462 lines (334 loc) · 13 KB

Security Assessment Executive Summary

Sovereign Network API Client - QUIC Architecture Analysis

Date: December 5, 2025 Status: CRITICAL ARCHITECTURE ISSUE IDENTIFIED


TL;DR

The API client library CANNOT connect to the ZHTP backend as currently designed.

  • Backend: QUIC/UDP (port 9334) - NO HTTP server
  • Client: JavaScript fetch() → HTTP/TCP
  • Result: Connection failure - incompatible protocols

Fix Required: Deploy HTTP-to-QUIC gateway OR implement native QUIC clients.


Critical Finding

The Architecture Mismatch

What You Think Happens:
┌─────────────────┐
│  API Client     │
│  fetch('http:') │ ──────X──────> Backend rejects TCP
└─────────────────┘       (no TCP listener)

What Actually Exists:
Backend is UDP-only (QUIC protocol)
No HTTP server on any TCP port
HttpCompatibilityLayer only works with HTTP-over-QUIC (HTTP/3)

Why It's Broken

  1. JavaScript fetch() uses TCP - cannot connect to UDP endpoints
  2. ZHTP backend is QUIC/UDP only - port 9334, no TCP listener
  3. Default URL is wrong - http://localhost:8000 (wrong protocol + wrong port)
  4. No browser support for QUIC - JavaScript has no native QUIC API

Proof from Code

Backend (Rust):

// zhtp/src/unified_server.rs line 86-87
// QUIC is ONLY ENTRY POINT
quic_mesh: Arc<QuicMeshProtocol>,
quic_handler: Arc<QuicHandler>,

// Line 16: TCP/UDP no longer used - QUIC-only architecture

Client (TypeScript):

// src/core/zhtp-api-core.ts line 28
this.fetchAdapter = fetchAdapter || ((url, options) => fetch(url, options));
// ❌ Standard fetch() cannot connect to UDP

Impact Assessment

Blocking Issues (P0)

Issue Impact Severity
P0-1: fetch() incompatible with QUIC Library is non-functional CRITICAL
P0-2: Wrong default URL/port All connections fail CRITICAL

Critical Security Issues (P1)

Issue Impact Severity
P1-1: Tokens in localStorage XSS can steal session tokens HIGH
P1-2: Credentials in request body Logging/XSS exposure HIGH
P1-6: QUIC connection hijacking Session takeover via IP spoofing HIGH
P1-7: Protocol confusion Security bypass attacks HIGH
P1-8: UDP amplification DDoS vector HIGH

Solution Architecture

Option 1: HTTP-to-QUIC Gateway (REQUIRED for Browsers)

Browser → Gateway (HTTP/TCP, port 8000) → ZHTP Backend (QUIC/UDP, port 9334)
        HTTP/1.1                        HTTP/3 over QUIC

Deploy gateway service to bridge protocols:

// gateway.js - Simple Node.js bridge
const http = require('http');
const { Http3Client } = require('@fails-components/webtransport');

const server = http.createServer(async (req, res) => {
  const quicClient = new Http3Client('https://localhost:9334');
  const response = await quicClient.fetch(req.url, {
    method: req.method,
    headers: req.headers,
    body: req.body
  });

  res.writeHead(response.status, response.headers);
  res.end(await response.text());
});

server.listen(8000);

Update API client configuration:

const config = new BrowserConfigProvider({
  zhtpNodeUrl: 'http://localhost:8000', // Gateway, not backend
  networkType: 'testnet'
});

Option 2: Native QUIC Client (React Native Only)

React Native → Native Bridge (Swift/Kotlin) → ZHTP Backend (QUIC/UDP)
             Network.framework/Cronet      Direct QUIC connection

Requires platform-specific QUIC implementation (see QUIC-TRANSPORT.md).


Original Assessment Re-Evaluation

Issues That Are NO LONGER RELEVANT

ID Original Issue New Status
P1-5 Unencrypted HTTP NOT APPLICABLE - QUIC mandates TLS 1.3
P2-3 SSRF attacks REDUCED RISK - QUIC uses UDP, different attack surface

Issues That STILL APPLY

ID Issue Status
P1-1 Session tokens in localStorage STILL CRITICAL - XSS risk
P1-2 Credentials in request body STILL CRITICAL - XSS/logging risk
P2-1 No input validation STILL HIGH - Injection risk
P2-2 Verbose error messages STILL HIGH - Information disclosure
P2-5 No CSRF protection STILL RELEVANT - If browser-based
P2-6 No rate limiting STILL HIGH - Brute force risk

New QUIC-Specific Vulnerabilities

P1-6: QUIC Connection Hijacking

Attack: Exploit connection migration to hijack sessions

  • QUIC allows connections to survive IP changes
  • Attacker could inject packets with same Connection ID from different IP
  • Requires cryptographic validation to prevent

Mitigation: Backend uses post-quantum cryptography (Kyber512 + Dilithium2)

P1-7: Protocol Confusion Attacks

Attack: Manipulate protocol detection to bypass security

  • Backend detects protocol by first bytes of stream
  • Attacker sends: ZHTP\x01GET /admin HTTP/1.1 (mixed protocols)
  • Could confuse router into accepting malicious payloads

Mitigation: Strict protocol validation, separate peer/client ports

P1-8: UDP Amplification Attacks

Attack: Use QUIC for DDoS amplification

  • Spoof victim's IP address
  • Send small QUIC request
  • Backend sends large response to victim

Mitigation: QUIC RFC 9000 protections (address validation, 3x amplification limit)

P2-8: Stream Exhaustion DoS

Attack: Open hundreds of streams per connection

  • Exhausts backend memory and file descriptors
  • Partial requests never completed

Mitigation: Configure quinn max_concurrent_bidi_streams limit


Immediate Actions Required

Must Do Before ANY Use

  1. Deploy HTTP-to-QUIC Gateway

    • Bridges HTTP/TCP (port 8000) to QUIC/UDP (port 9334)
    • Required for browser compatibility
    • Can be Node.js, Go, or Nginx with QUIC module
  2. Update Default Configuration

    • Change URL from http://localhost:8000 to gateway address
    • Add connection validation with clear error messages
  3. Add Connection Testing

    async testConnection(): Promise<{ connected: boolean; error?: string }> {
      try {
        await this.getProtocolInfo();
        return { connected: true };
      } catch (error) {
        return {
          connected: false,
          error: `Cannot connect to ZHTP backend. Ensure HTTP-to-QUIC gateway is running on port 8000.`
        };
      }
    }

Must Do Before Production

  1. Fix Session Token Storage (P1-1)

    • Move from localStorage to httpOnly cookies
    • Or use memory-only storage with session expiration
  2. Secure Credential Handling (P1-2)

    • Use Credential Management API
    • Or implement request body encryption
  3. Add Input Validation (P2-1)

    • Use Zod or Yup for all request parameters
    • Validate on client before sending
  4. Generic Error Messages (P2-2)

    • Never expose internal errors to users
    • Log detailed errors server-side only
  5. Implement Rate Limiting (P2-6)

    • Client-side request throttling
    • Exponential backoff on failures

Architecture Decision

Recommended: Gateway + Native Hybrid

Browser Applications:
  ↓ HTTP/1.1 over TCP
Gateway Service (port 8000)
  ↓ HTTP/3 over QUIC
ZHTP Backend (port 9334)

React Native Applications:
  ↓ Direct QUIC connection
ZHTP Backend (port 9334)

Benefits:

  • Browser compatibility (via gateway)
  • Native performance (direct QUIC for mobile)
  • Post-quantum cryptography for native clients
  • Gradual migration path

Tradeoffs:

  • Gateway is single point of failure
  • TLS termination at gateway (no end-to-end encryption for browsers)
  • More complex deployment

Backend Security Analysis

What the Backend Does RIGHT

QUIC-only architecture - Mandatory TLS 1.3 encryption ✅ Post-quantum cryptography - Kyber512 + Dilithium2 ✅ Rate limiting - 10 handshakes per IP per 60 seconds ✅ Connection limits - Max 10,000 PQC connections ✅ Protocol detection - Validates incoming protocol on each stream ✅ Idle timeouts - 60s client, 300s peer connections ✅ Amplification protection - QUIC RFC 9000 compliant

Backend Gaps

⚠️ No per-connection stream limits - Could exhaust resources ⚠️ Protocol confusion risk - Mixed protocol payloads ⚠️ QUIC fingerprinting - Connection parameters leak implementation ⚠️ Connection migration - Needs additional validation


Documentation Updates Required

Update QUIC-TRANSPORT.md

INCORRECT (line 159):

- **HTTP Fallback**: 9333/TCP (if QUIC unavailable)

CORRECT:

There is NO HTTP fallback. QUIC/UDP is mandatory.

For browser compatibility:
1. Deploy HTTP-to-QUIC gateway
2. Gateway accepts HTTP/TCP on port 8000
3. Gateway forwards via HTTP/3 (QUIC) to backend port 9334

Add to README.md

## ⚠️ CRITICAL: Architecture Requirements

**This library cannot connect directly to the ZHTP backend from browsers.**

The ZHTP backend uses QUIC (UDP) protocol, but JavaScript fetch() uses HTTP (TCP).

You MUST deploy an HTTP-to-QUIC gateway for browser clients:

1. Start gateway: `node gateway.js` (listens on port 8000/TCP)
2. Gateway bridges to backend (port 9334/UDP)
3. API client connects to gateway, not backend directly

For React Native: Implement native QUIC client (see QUIC-TRANSPORT.md)

Testing Checklist

Pre-Deployment

  • Gateway service deployed and running
  • API client can connect via gateway
  • Authentication flow works (signup/login)
  • All 52 API methods functional
  • Error handling (no stack traces exposed)
  • Rate limiting enforced
  • Token storage reviewed

QUIC Security Testing

  • Connection establishment (HTTP → Gateway → QUIC)
  • Protocol detection accuracy
  • HTTP-over-QUIC compatibility
  • Connection migration behavior
  • Amplification attack resistance
  • Stream limit enforcement
  • Idle timeout handling
  • Protocol confusion tests

Penetration Testing

  • Protocol confusion: ZHTP\x01GET / HTTP/1.1
  • Connection hijacking via IP spoofing
  • Stream exhaustion (open 1000+ streams)
  • Amplification attack simulation
  • PQC handshake manipulation
  • Certificate validation bypass attempts

Compliance Status

OWASP Top 10

Issue Status Notes
A01: Broken Access Control ⚠️ Review Needed Session management
A02: Cryptographic Failures ❌ Vulnerable Tokens in localStorage
A03: Injection ❌ Vulnerable No input validation
A04: Insecure Design ❌ Critical Architecture mismatch
A05: Security Misconfiguration ❌ Vulnerable Wrong defaults
A06: Vulnerable Components ✅ Good Dependencies current
A07: Authentication Failures ⚠️ At Risk Credentials in body
A08: Software/Data Integrity ✅ Good TypeScript safety
A09: Logging Failures ⚠️ Unknown Client-side limited
A10: SSRF ⚠️ Reduced QUIC architecture

Overall Score: 3/10 Good, 4/10 Vulnerable, 3/10 At Risk


Cost-Benefit Analysis

Option 1: HTTP-to-QUIC Gateway

Effort: 1-2 weeks Cost: Low (simple Node.js service) Benefits:

  • Browser compatibility immediately
  • No client changes required
  • Easy to deploy

Tradeoffs:

  • Gateway is SPOF
  • No end-to-end encryption
  • Limited QUIC benefits

Option 2: Native QUIC Clients

Effort: 2-4 weeks per platform Cost: Medium (Swift + Kotlin development) Benefits:

  • Full QUIC benefits (0-RTT, multiplexing)
  • Post-quantum cryptography
  • Best performance

Tradeoffs:

  • Complex native code
  • Platform-specific bugs
  • Maintenance overhead

Recommendation: Hybrid Approach

  1. Deploy gateway for browsers (quick win)
  2. Implement native clients for React Native (better UX)
  3. Deprecate gateway when WebTransport is widely supported

Timeline: 2-3 weeks total Cost: Low-Medium ROI: High (functional library + security improvements)


Conclusion

The Sovereign Network API Client has a fundamental architecture incompatibility that prevents it from functioning.

Quick Fix (1 week): Deploy HTTP-to-QUIC gateway Proper Fix (2-4 weeks): Implement native QUIC clients for React Native Security Fixes (1-2 weeks): Address P1/P2 issues (tokens, credentials, validation)

Total Estimated Effort: 4-7 weeks for complete solution

Priority Order:

  1. Gateway deployment (BLOCKING)
  2. Security fixes P1-1, P1-2 (CRITICAL)
  3. Input validation P2-1 (HIGH)
  4. Native QUIC clients (IMPROVEMENT)
  5. Remaining P2 issues (HARDENING)

Contact for Questions

For technical questions about this assessment:

  • Review full report: SECURITY-ASSESSMENT-REVISED.md
  • Check backend code: The-Sovereign-Network/zhtp/src/unified_server.rs
  • Check client code: sovereign-network-api-client/src/core/zhtp-api-core.ts

Next Steps: Deploy gateway and address P0/P1 issues before ANY production use.