You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WebCrypt is a well-structured zero-dependency cryptography library with high test coverage (174 tests passing, ~89.6% statement coverage / ~77.9% branch coverage). A comprehensive audit of the codebase and previous plan identified 7 critical/high security issues, 3 performance bottlenecks, and 4 documentation/TypeScript/infrastructure gaps.
Notably, empirical verification confirms .gitignore and .github/workflows/ci.ymlalready exist in the repository (contrary to initial plan assumptions) but require enhancement. This updated plan refines all tasks across 4 phases: Critical Security Fixes → High-Priority Security → Performance Improvements → Infrastructure, TypeScript & Documentation Enhancements.
Issue:dilithiumVerify() currently returns true for any signature whose size matches signatureSize, providing no verification.
Fix: Implement signature validation matching dilithiumSign() stub logic — verify that the signature bytes match the SHA-3 hash signature computed from the message and private key/public key stub material. Return false if verification fails.
Impact: Eliminates false positive signature verifications in stub mode.
Step 1.2: Clean up deprecated key cache stubs in WebCryptAsym
Files:src/WebCryptAsym.js, src/WebCryptAsym.d.ts
Issue: Deprecated stub methods (_getCachedKey(), _cacheKey(), clearKeyCache(), stopAutoCleanup()) exist in WebCryptAsym.js while active caching lives in WebCrypt.js.
Fix: Remove unused interior code, mark methods explicitly with @deprecated JSDoc annotations, and update WebCryptAsym.d.ts to maintain clean backwards compatibility without misleading users.
Impact: Eliminates dead code confusion and aligns TypeScript definitions.
Step 1.3: Add explicit runtime warnings and JSDoc for Argon2 fallback paths
Files:src/WebCryptAsym.js, src/WebCryptAsym.d.ts
Issue:deriveKeyArgon2() / deriveKeyArgon2Enhanced() fall back to PBKDF2.
Fix: Add JSDoc @deprecated tags to deriveKeyArgon2 recommending external argon2-browser package or deriveKeyPBKDF2, and ensure console.warn() is consistently emitted on invocation.
Impact: Prevents false assumption of Argon2 security level.
Issue:String.fromCharCode.apply(null, bytes.subarray(...)) risks exceeding V8 call stack size on large buffers (>32KB).
Fix: Implement robust chunked base64 conversion loop using max 32KB chunks with explicit loop indexing rather than .apply().
Impact: Prevents call stack overflow errors during large payload base64 encoding.
Step 2.2: Fix fixed salt predictability for HMAC key derivation
Files:src/WebCrypt.js, src/WebCryptAsym.js
Issue:DEFAULT_HMAC_SALT is a fixed string, producing predictable key derivation across instances when no custom salt is supplied.
Fix: For non-WebRTC HMAC key derivation without password, generate a random 16-byte salt per key generation instance or require explicit salt. Document WebRTC fixed salt constraints with @warning annotations.
Impact: Prevents predictable key generation across different HMAC deployments.
Step 2.3: Fix authenticatePoly1305 unsupported Web Crypto algorithm crash
Files:src/WebCryptAsym.js, src/WebCryptAsym.d.ts
Issue:{ name: "Poly1305" } throws NotSupportedError in Web Crypto API.
Fix: Update authenticatePoly1305() to throw a clear descriptive Error ("Poly1305 is not supported by standard Web Crypto API; use signHMAC() instead") or provide Poly1305 via standard HMAC fallback, with @deprecated JSDoc tags.
Impact: Replaces unhandled Web Crypto exceptions with actionable error messages and guidance.
Fix: Verify and ensure all local memory databases (.state-memory-mcp/, .vision-memory-mcp/), build outputs (dist/), test coverage (coverage/), logs, and environment files (.env) are strictly ignored.
Impact: Clean git state and prevention of accidental key/db commits.
Fix: Update workflow to include: Node.js 18.x, 20.x, 22.x matrix, npm run format:check, unit test execution, coverage enforcement check, and npm audit --audit-level=high step.
Impact: Continuous integration quality gate with automated security auditing.
__tests__/WebCryptPQC*.test.js — Dilithium verification stub test validation
Documentation & Infrastructure Files
README.md — API documentation fixes
.gitignore — Ensure coverage and memory db files ignored
.github/workflows/ci.yml — Enhanced CI pipeline
Verification Steps
Run unit test suite:npm test — verify all 174+ unit tests pass cleanly.
Run test coverage:npm run test:coverage — target ≥90% statements and ≥80% branches.
Verify TypeScript compilation & build:npm run build — confirm tsup generates ESM, CJS, and .d.ts without errors.
Verify formatting:npm run format:check — ensure Prettier compliance across all source and test files.
Benchmark HMAC generation: Validate generateHmacKeySHA3() completion time under reduced iterations.
Verify Base64 stack safety: Test roundtrip on payload > 64KB without call stack errors.
Decisions & Assumptions
PQC remains stub implementation: Kyber and Dilithium remain polyfill stubs using SHA-3 hashing; production PQC requires external liboqs-js.
Argon2 recommendation: Web Crypto API does not natively support Argon2id; PBKDF2 with high iterations remains the built-in fallback while JSDoc points to argon2-browser.
Infrastructure files exist:.gitignore and .github/workflows/ci.yml were confirmed present in repository audit and will be enhanced rather than created from scratch.
TypeScript declaration parity: All .js changes must be reflected in corresponding .d.ts files to maintain strict type safety.