Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ The format follows Keep a Changelog and the package uses semantic versioning.

## Unreleased

- Guarded failed-decryption cleanup against deleting a changed committed
persistent-cache row. Eligible concrete built-in reads compare known
metadata and encrypted bytes in the same transaction as any delete.
Unchanged corrupt data is still removed; successful reads, ordinary misses,
public deletion and stored formats are unchanged. Cleanup adds a failure-path
lookup and result/comparison work. Subclasses, delete overrides and non-binary
original snapshots retain unconditional cleanup and its replacement races.

- Ordered admitted persistent-cache mutations within each tiered cache.
Same-key operations wait for predecessors; all-cache clear and destruction
wait for earlier work and fence later admitted mutations. Unrelated keys
Expand Down
361 changes: 361 additions & 0 deletions benchmarks/conditional-corrupt-cache-cleanup/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { execFileSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { defineConfig } from "vitest/config";

const root = fileURLToPath(new URL("../../", import.meta.url));
const target = fileURLToPath(new URL("../../src/browser/cache.ts", import.meta.url)).replaceAll("\\", "/");
const { baseline } = JSON.parse(readFileSync(new URL("./protocol.json", import.meta.url), "utf8"));
const source = execFileSync("git", ["--no-pager", "show", `${baseline}:src/browser/cache.ts`], { cwd: root, encoding: "utf8" });
export default defineConfig({
root,
plugins: [{
name: "exact-baseline-corrupt-read-cache", enforce: "pre",
load(id) { return id.replaceAll("\\", "/").split("?")[0] === target ? source : null; },
}],
test: { include: ["tests/browser-cache-corrupt-read.test.ts"] },
});
433 changes: 433 additions & 0 deletions benchmarks/conditional-corrupt-cache-cleanup/fixtures.ts

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions benchmarks/conditional-corrupt-cache-cleanup/native-fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { IndexedDbObjectCache } from "../../src/browser/cache.js";
import { runTrial, type Policy } from "./fixtures.js";

export const encryptedScenarios = [
"replaced-set", "same-metadata-replacement", "same-iv-new-ciphertext",
"peer-replacement", "two-failed-readers", "unchanged-corrupt",
"destroy-recreate", "successful-read",
] as const;
export function runEncryptedScenario(scenario: typeof encryptedScenarios[number], policy: Policy) {
const limit = encryptedScenarios.indexOf(scenario) % 2 === 0 ? "bounded" : "unbounded";
return runTrial(IndexedDbObjectCache, scenario, policy, limit);
}
export function runAtomicCleanup(policy: Policy) {
return runTrial(IndexedDbObjectCache, "unchanged-corrupt", policy,
policy === "content" ? "bounded" : "unbounded", "head", { atomic: true });
}
export function runReopenedConnection(policy: Policy, limit: "bounded" | "unbounded") {
return runTrial(IndexedDbObjectCache, "replaced-set", policy, limit, "head",
{ closeDuringRead: true });
}
101 changes: 101 additions & 0 deletions benchmarks/conditional-corrupt-cache-cleanup/protocol.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"schemaVersion": 1,
"experiment": "P15: conditional cleanup after failed cache decryption",
"baseline": "09aa634a235bba3c6e06fda9dbe47de962b7237a",
"scope": "Failed-decryption cleanup in the concrete built-in IndexedDbObjectCache with its original delete method and binary encrypted snapshots; no new public option, format, dependency, infrastructure, CI workflow or host runtime change",
"hypothesis": "Compare the currently stored known metadata and encrypted bytes with the failed-read snapshot inside the same readwrite transaction as any deletion, so stale cleanup cannot remove a committed changed row",
"discovery": "Real WebCrypto authentication failure with fake IndexedDB reproduced loss of a newer committed replacement under content/locations and bounded/unbounded persistence. Existing tiered invalidation returned the newer memory value but the next cold read missed.",
"rules": [
"An eligible failed read returns a miss and deletes only a currently matching snapshot: key, etag, cachedAt, checkedAt, immutable, namespace, cacheKey, IV bytes and ciphertext bytes",
"The comparison lookup and any conditional delete use one objects-store readwrite transaction, with the possible delete issued synchronously in the lookup success handler",
"A missing, metadata-changed or binary-changed current row is preserved; no retry or reread loop is added",
"Unchanged schema-shaped corrupt data is still deleted; successful reads, ordinary misses and public delete retain their existing behaviour",
"Preserve delegated legacy cleanup for non-concrete subclasses, an overridden public delete method and snapshots with non-binary crypto fields; these compatibility exceptions do not gain replacement protection",
"Only binary values may use IndexedDB key comparison; an incomparable current payload must be conservatively preserved rather than abort cleanup",
"Do not change device-key generation/retention, namespace encoding, eviction/quota counters, tiered read fences, mutation ordering, admission/fallback or destroy rejection",
"An eligible cleanup adds one objects-store lookup inside the existing cleanup transaction; comparison and transient storage-result copies are real failure-path costs",
"No background queue, historical state, new entry clone, cancellation, timeout, tombstone, stored generation field or database-version change",
"This is protection against stale failed-read deletion, including an already committed peer replacement; it is not read linearizability, cross-instance mutation ordering, durable logout, arbitrary damaged-record repair or a corruption-frequency claim"
],
"matrix": {
"policies": ["content", "locations"],
"limits": ["unbounded", "bounded"],
"shapes": ["head", "branch"],
"replicates": 3,
"memory": { "maxEntries": 64, "maxBytes": 1048576 },
"persistentLimits": { "maxEntries": 64, "maxBytes": 1048576 },
"scenarios": [
"replaced-set",
"same-metadata-replacement",
"new-iv-same-ciphertext",
"same-iv-new-ciphertext",
"metadata-only-change",
"destroy-recreate",
"peer-replacement",
"two-failed-readers",
"unchanged-corrupt",
"already-deleted",
"cleared",
"destroyed",
"subclass-delete-control",
"malformed-binary-control",
"successful-read",
"cache-miss"
],
"protectedScenarios": [
"replaced-set", "same-metadata-replacement", "new-iv-same-ciphertext",
"same-iv-new-ciphertext", "metadata-only-change", "destroy-recreate",
"peer-replacement", "two-failed-readers"
],
"changedButStillCorrupt": [
"new-iv-same-ciphertext", "same-iv-new-ciphertext", "metadata-only-change"
],
"legacyCompatibilityExceptions": ["subclass-delete-control", "malformed-binary-control"],
"trialsPerArm": 384,
"implementation": "Real WebCrypto and fake IndexedDB in the comparative matrix; actual browser IndexedDB qualified separately",
"ordering": "Fresh uniquely named database and caches per trial; alternate arm order by recipe, policy, limits, shape and replicate; hold actual decryption before completing its genuine failure, commit the intervening action, then release held readers newest first",
"measurement": "Record synthetic known metadata and binary identity, encrypted states before/after cleanup, expected retention/deletion, immediate tiered returns/memory, cold verification, scoped transaction/request events, crypto outcomes, root-memory methods/copies, errors/counters and device-key counts; keep fixture/inspection work separate",
"identity": "Random ciphertext differs between arms. Pair gates compare declared logical states/actions, not equality of independently encrypted bytes. Each row retains enough binary identity to verify its own comparison and retention decisions.",
"namespaceControls": "Seed another same-namespace key and the same logical key in a distinct similar namespace. The other namespace must always survive; whole-namespace clear/destroy intentionally removes the first namespace's other key.",
"baselineExpectation": "All eight protected recipes fail retention in the baseline: 192/384 qualifying outcomes versus candidate 384/384. Three changed-but-still-corrupt recipes distinguish retention from a usable cold result; baseline cold-read correctness is 264/384. Legacy exceptions intentionally retain existing cleanup.",
"timers": "Diagnostic deadlines only; no latency, throughput, heap, allocation-size, GC timing, production-frequency or provider-cost inference"
},
"hardGates": [
"Candidate preserves every changed eligible snapshot and removes every unchanged corrupt snapshot; baseline reproduces all 192 protected retention failures",
"All expected immediate-memory values, pending-read returns, cold results, namespace/key states, fallback outcomes and metrics match the prospective recipe",
"Successful-read and cache-miss controls preserve exact production transaction/request, memory and copy work",
"Eligible failure cleanup uses one readwrite transaction, one additional objects lookup, and at most one matching conditional delete; no extra transaction, retry, put or key change",
"A competing raw replacement queued from the cleanup lookup success event survives; assert that comparison and deletion belong to the same transaction",
"Focused tests cover sliced binary views, same metadata, changed IV/ciphertext, special keys, cleanup transaction abort, subclass/instance/prototype delete overrides and the stated legacy fallbacks",
"Both policies and bounded/unbounded modes qualify; immutable branch content remains immutable",
"Chromium, Firefox and WebKit each pass sixteen selected encrypted race/control cases plus two queued-replacement atomicity cases; selected modes cover both bounded and unbounded adapters",
"All 312 existing mutation, namespace, admission, hydration, ownership, client, connection and publication controls, root/collector/native types, package and canonical documentation pass; full normal exact-head CI remains required",
"Publish the protocol before production edits and push source/collector before detached comparative capture; retain all captures and qualification attempts without overwrite",
"Independently verify every raw state/identity/action/event/count and all pair gates, CSV rows, graph bars and report tables"
],
"mergeDecision": {
"threshold": 85,
"allHardGatesMandatory": true,
"weights": {
"cleanupCorrectness": 40,
"compatibilityAndFailureIsolation": 25,
"reproducibleEvidence": 20,
"scopeAndSimplicity": 15
},
"benefitCriterion": "Prevent stale failed-decryption cleanup from discarding a changed committed normal built-in encrypted row while retaining ordinary corrupt-row cleanup and unchanged successful-read work",
"claimBoundary": "One-row conditional cleanup only. Extra failed-read lookup, object-store lock duration, binary comparison and transient result retention are real costs. Legacy exceptions remain unprotected, and a preserved changed corrupt row can fail and be removed by its own later read."
},
"limits": {
"cloudNetwork": false,
"maximumRecordedObjectRequests": 50000,
"maximumRunMinutes": 5,
"operationDeadlineMilliseconds": 5000,
"overwriteEvidence": false
},
"sources": [
"https://developer.mozilla.org/en-US/docs/Web/API/IDBTransaction",
"https://developer.mozilla.org/en-US/docs/Web/API/IDBFactory/cmp",
"https://github.com/Jason-Doyle/thimble/blob/09aa634a235bba3c6e06fda9dbe47de962b7237a/src/browser/cache.ts",
"https://github.com/Jason-Doyle/thimble/blob/09aa634a235bba3c6e06fda9dbe47de962b7237a/docs/BROWSER-CACHE.md"
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading