LawForge
Legal document generator with compliance-focused security, attorney-client privilege protections, audit logging, and 26 legal templates.
Zone: staging/ Version: 1.0.0
Overview
LawForge generates legal documents from 26 compliance-ready templates across six categories: Administrative/Client Intake (5), Litigation (8), Estate Planning (3), Real Estate (3), Corporate (4), and Correspondence (3). A Template Wizard handles dynamic field prompts with tab/enter navigation. An Edit Wizard resumes incomplete templates with progress tracking. Folder Profiles persist per-folder auto-fill for firm name, attorney, and client.
All data stays client-side — no cloud sync. Offline support via Service Worker.
Tech Stack
| Component | Technology |
|---|---|
| Language | Vanilla JS (ES6+) |
| Persistence | IndexedDB (LawForgeDB v5, 5 object stores) |
| Testing | Vitest 2.1.9 |
| CI/CD | GitHub Actions (security.yml) |
| Zone | staging/ |
No external runtime dependencies. The security module is IIFE-wrapped and fully self-contained.
Architecture
| File | Purpose |
|---|---|
lawforge_v1.html | Single-page application entry point |
app.js | Document management, UI, Template Wizard (2375 lines) |
law-templates.js | 26 template definitions with field metadata |
security.js | Input sanitization, sensitive field detection, session management (458 lines) |
db.js | IndexedDB wrapper and CRUD operations |
crypto.js | Field encryption — IIFE (LawForgeCrypto) |
service-worker.js | Offline support |
See also: indexeddb-migration-protocol for IndexedDB versioning and migration strategy.
IndexedDB Stores
Five object stores in LawForgeDB v5:
documents— content, template type, metadatafolders— folder hierarchyversions— document snapshots (default 50 per document)settings— user preferences and vault saltaudit_log— event records (capped at 5000 entries)
Security
The security module (security.js) handles:
- Session management: 15-minute inactivity warning, 30-minute hard lock
- Input sanitization: Blocks script injection, event handlers, HTML, data URIs, null bytes (recursive scrubbing)
- Sensitive field detection: Auto-masking of SSN, TIN, bank accounts, credit cards, passwords
- Data leak prevention: Print/copy/drag-drop warnings and interception, clipboard copy notification logging
- Confidentiality banners: Document-level attorney-client privilege notices
Encryption Foundation (Phase 3.4)
Field encryption on the document content field:
- Algorithm: PBKDF2-SHA256 (310,000 iterations) + AES-256-GCM
- Implementation: Web Crypto API (SubtleCrypto) — no external dependencies
- Key held in memory only; never persisted to disk
- Salt stored as base64 in IndexedDB
settingsstore under keyvault_salt DB_SECUREindb.jswrapssaveDocument/getDocument— title, type, and dates remain plaintext for sidebar search- Migration-safe: existing docs without
_enc: trueflag are returned as-is - DOM vault overlay built with DOM methods (no innerHTML) to satisfy security hook
- SubtleCrypto requires HTTPS or localhost — vault gracefully disabled otherwise with console warning
See also: 3-scanner-security-architecture for the CI security scanning setup (TruffleHog + Trivy + Semgrep).
Audit & Compliance
Comprehensive audit log (max 5000 entries) covering:
DOC_CREATE,DOC_SAVE,DOC_DELETE,DOC_EXPORTTEMPLATE_GENERATE,SENSITIVE_FIELDdetectionSESSION_LOCKED,CLIPBOARD_COPY,PRINT_ATTEMPT
Audit Log Viewer modal provides search, filter by event type, export, and prune functions. Timestamp and user context on all events.
Export Formats
Six export formats: Markdown, TXT, HTML, PDF, JSON, DOCX.
Current Status
Phase: Staging (Phase 3.4 complete as of 2026-03-13)
Completed
- 26-template system across 6 legal categories
- Security module: session management, input sanitization, sensitive field detection
- Audit logging with viewer modal
- Offline support via Service Worker
- Phase 2 compliance: security.yml (TruffleHog + Trivy + Semgrep), SECURITY.md, PR template, CODEOWNERS
- Phase 3.4: Encryption foundation (PBKDF2 + AES-256-GCM via SubtleCrypto)
Known Gaps
- Test coverage below 60% target (remediation planned Phase 4)
- CI/CD lint+test pipeline pending (security.yml deployed; general CI next)
- RBAC design deferred to Phase 6.2 (roles: admin/editor/viewer, document-level permissions, immutable audit log export)
- Audit log capped at 5000 entries; no backup/restore mechanism
- Session lock timeout (30 minutes) not configurable via UI
Lessons Learned
- SubtleCrypto availability: Web Crypto API requires HTTPS or localhost. A graceful fallback (console warning, vault disabled) is required for environments that don’t meet this constraint.
- Calibration mode for new staging repos: All new staging repos start security CI in calibration mode to establish baseline before switching to enforcing mode. Calibration period set through 2026-04-13.
- DOM construction over innerHTML: Security hook flags innerHTML usage. Building vault overlays with DOM methods (
createElement,appendChild) avoids the hook entirely. - Encryption migration safety: Storing an
_enc: trueflag on encrypted documents allows migration-safe reads — unencrypted legacy documents are returned as-is without errors.