Dev.to Security πŸ” Cybersecurity πŸ‘ 2 πŸ“– 3 min read

Browser-Local WebCrypto AES-256-GCM Autofill Vaults and AcroForm Coordinate Mapping Without Cloud Custody

Tax filings (W-9, 1099 onboarding), university registrar packets, rental leases, and visa applications concentrate an individual's highest-value identity tokens into a single PDF: legal name, date of birth, tax identifie

Tax filings (W-9, 1099 onboarding), university registrar packets, rental leases, and visa applications concentrate an individual's highest-value identity tokens into a single PDF: legal name, date of birth, tax identifiers, addresses, and handwritten signatures. Uploading those documentsβ€”or storing reusable profile attributesβ€”on third-party multi-tenant SaaS portals exposes sensitive records to remote logs and vendor breach surfaces.

Yet manually retyping the exact same forty fields across twelve forms wastes hours. The browser already ships the primitives needed for instant reuse with zero cloud custody: WebCrypto (window.crypto.subtle) paired with device-local IndexedDB.

1. Threat Model & Cryptographic Architecture

Instead of syncing user profiles to a backend database, a browser-local autofill vault encrypts serialized form profiles and transparent signature PNGs in device memory prior to IndexedDB persistence:

Ciphertext = AES-256-GCM(Key_256, Nonce_96, JSON(ProfileFields)) + AuthTag_128

Key architectural invariants:

Security Property Traditional Cloud Form Portals Browser-Local WebCrypto AES-256-GCM Vault
Storage Location Remote SaaS account database Device-local browser IndexedDB
Cryptographic Cipher Plaintext session or vendor-managed WebCrypto AES-256-GCM + unique 96-bit IV
Signature Reuse Privacy Saved signature stored server-side Transparent PNG encrypted locally
Shared Machine Hygiene Persists until remote deletion 1-click instant local vault wipe

Reference WebCrypto AES-256-GCM Seal & Open Flow

Using a non-exportable CryptoKey (extractable: false) generated via crypto.subtle.generateKey prevents JavaScript callers from ever serializing the raw symmetric key bytes out of the browser's key handle store, while a fresh 12-byte CSPRNG IV on every write prevents nonce reuse:

export async function generateVaultKey(): Promise<CryptoKey> {
  return crypto.subtle.generateKey(
    { name: 'AES-GCM', length: 256 },
    false, // non-exportable key handle
    ['encrypt', 'decrypt'],
  );
}

export async function sealProfile(key: CryptoKey, profile: Record<string, unknown>) {
  const iv = crypto.getRandomValues(new Uint8Array(12)); // 96-bit nonce
  const plaintext = new TextEncoder().encode(JSON.stringify(profile));
  const ciphertext = await crypto.subtle.encrypt(
    { name: 'AES-GCM', iv, tagLength: 128 },
    key,
    plaintext,
  );
  return { iv: Array.from(iv), ciphertext: Array.from(new Uint8Array(ciphertext)) };
}

export async function openProfile(
  key: CryptoKey,
  sealed: { iv: number[]; ciphertext: number[] },
): Promise<Record<string, unknown>> {
  const iv = new Uint8Array(sealed.iv);
  const data = new Uint8Array(sealed.ciphertext);
  const plaintext = await crypto.subtle.decrypt(
    { name: 'AES-GCM', iv, tagLength: 128 },
    key,
    data,
  );
  return JSON.parse(new TextDecoder().decode(plaintext));
}

Because AES-GCM appends a 128-bit authentication tag (tagLength: 128), any ciphertext modification in IndexedDB fails crypto.subtle.decrypt immediately with an OperationError rather than returning corrupted field values.

2. Solving Cryptic AcroForm Widget Identifiers

Cryptographic custody only solves half the workflow. In practice, government tax forms and institutional PDFs rarely use readable AcroForm field names like first_nameβ€”form generators routinely emit opaque identifiers such as topmostSubform[0].Page1[0].f1_14[0] or TextField19.

To map vault attributes and natural-language/voice inputs reliably:

  1. AcroForm Dictionary + Text-Span Geometry Parse: Extract every interactive widget dictionary (fieldName, fieldType, Rect in 72 DPI PDF user-space points) alongside visible nearby page text spans ("Legal Business Name", "Tax Classification", "Effective Date").
  2. Visual Overlay Verification: Highlight mapped entries directly on the rendered canvas before flattening or exporting, allowing 1-point arrow-key coordinate nudges for tight checkboxes and printed boxesβ€”crucial for non-interactive flat PDF scans where fields do not exist in the AcroForm tree.
  3. Standard ISO 32000 Export: Write crisp vector text and signatures cleanly into a standard PDF (0 corner watermarks, 0 server roundtrips), and provide 1-click local vault erasure for shared lab or library machines.

References & Interactive Tools

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.