Skip to content

fix: guards and documentation from the 2.1.0 review, and runtime smoke tests in CI - #31

Merged
adelzemzemi merged 7 commits into
mainfrom
fix/2.1-review-findings
Nov 20, 2026
Merged

adelzemzemi merged 7 commits into
mainfrom
fix/2.1-review-findings

Conversation

@adelzemzemi

Copy link
Copy Markdown
Owner

Fixes and documentation from a review of 2.1.0. One commit per finding.

Changes

1. Passwords are not Unicode-normalized: documented and pinned (docs)

A password typed in NFC (café, precomposed) does not decrypt data written with its NFD form (e + U+0301): DECRYPTION_FAILED. How a password becomes bytes is not changed: normalizing inside the package would change the key of every non-ASCII password already in use and would need a new envelope version.

  • README (Encryption section) and the SECURITY.md threat model tell callers to normalize consistently before every call, e.g. password.normalize('NFC').
  • New test: NFC and NFD forms are different passwords in both directions, and normalizing on both sides makes them agree. The frozen vector V2_UNICODE_PASSWORD already pinned the NFD side against frozen bytes.

2. Non-string plaintext and context are refused (fix)

From untyped JavaScript, encrypt(undefined, pw) encrypted "", encrypt({a:1}, pw) encrypted "[object Object]", encrypt(123, pw) encrypted "123"; context: 42 was coerced and any two objects bound to the same "[object Object]".

  • New guard assertPlaintext in src/crypto/guards.ts; assertContext now also checks the type.
  • encrypt() refuses a non-string plaintext; encrypt(), decrypt(), rewrap() (both context and previousContext) and AesGcmEncryptor refuse a non-string context. All with INVALID_ARGUMENT.
  • undefined still means no context (tested). AesGcmEncryptor and SecureStorage serialize to JSON and always pass a string plaintext; their existing tests pass unchanged.

3. Per-call iterations above the instance's maxIterations is refused (fix)

new AesGcmEncryptor({ maxIterations: 600_000 }).encrypt(data, pw, { iterations: 700_000 }) succeeded, then the same instance refused to read it. AesGcmEncryptor.encrypt() now refuses the write with INVALID_ARGUMENT, the code and wording style of the existing constructor check, before any key derivation. Without a maxIterations, per-call counts are unchanged.

4. CI proves the runtimes the README names (ci)

  • New job Smoke-test the packed tarball on Bun / Deno: builds, packs, installs the tarball into a consumer project, and runs tests/runtimes/installed.mjs under the runtime.
  • The build job runs the same smoke test under Node against the tarball, and loads dist/index.mjs in headless Chrome (tests/runtimes/chromium.mjs).
  • One shared check, tests/runtimes/smoke.mjs: round-trip, mismatched context and wrong password fail with DECRYPTION_FAILED, a frozen 1.x ciphertext and a frozen context-bound 2.x ciphertext (copied from tests/crypto/test-vectors.test.ts) still decrypt, a SecureStorage round-trip.
  • Browser: playwright-core (new dev dependency, no transitive deps) drives the Chrome preinstalled on the runner via channel: 'chrome'; nothing is downloaded, and files are served by request interception on a localhost origin, so no server is started.
  • Actions pinned by SHA resolved with gh api: oven-sh/setup-bun@0c5077e… (v2.2.0), denoland/setup-deno@22d081f… (v2.0.5). Timeouts and permissions: contents: read as elsewhere.
  • README "How it is checked" gains one bullet stating this.

5. SECURITY.md review history (docs)

  • The 2.0.0 review was dated "August 2026". Git has no commit between 2026-09-10 and 2026-11-17; the review's fixes landed on 2026-11-17 (f189a36 fix: close the gaps found by the pre-release security review), and the entry itself was written in e0c662f the same day. Changed to November 2026.
  • Entries added for 2.1.0 (the maxIterations read cap) and for this pull request.

Semver

Proposed: 2.1.1 (patch). Items 2 and 3 are guards that reject input which was silently corrupted before (a plaintext or context that lost its value, a write the encryptor could not read back); 1 and 5 are documentation; 4 is CI only. No format, key derivation, AAD or signature change. package.json is not bumped.

Tested

  • npm run verify: green locally (type-check, lint, format, 266 tests, coverage 100 % lines/functions/statements and 97.84 % branches, build, attw, publint).
  • New tests for items 2 and 3 were run against the previous source and fail there.
  • Locally: the Chrome smoke passed (Chrome 158) and the Node tarball smoke passed; a deliberately broken vector makes the Chrome run fail. Bun and Deno are proven by this pull request's CI only.
  • Not tested: Firefox and Safari/WebKit.

@adelzemzemi adelzemzemi self-assigned this Nov 20, 2026
@adelzemzemi

Copy link
Copy Markdown
Owner Author

Review: no blocking finding. Pushed one commit on top: the runtime claim is narrowed to what CI runs (Bun, Deno, headless Chrome; Firefox and Safari are not tested), and the release is prepared as 2.1.1 (version, changelog date, SECURITY.md entry). The Bun and Deno smoke jobs are now required checks on main.

While allowLegacy is on, an envelope above the cap is still tried once as a
headerless 1.x value at 100,000 iterations before INVALID_ITERATIONS. The 2.1.0
wording said no key was derived at all, which only holds with allowLegacy: false.
@adelzemzemi
adelzemzemi merged commit dc58a6e into main Nov 20, 2026
10 checks passed
@adelzemzemi
adelzemzemi deleted the fix/2.1-review-findings branch November 20, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant