feat: content hashes on document versions + tamper-evident project export manifest#181
Open
b1rdmania wants to merge 1 commit into
Open
feat: content hashes on document versions + tamper-evident project export manifest#181b1rdmania wants to merge 1 commit into
b1rdmania wants to merge 1 commit into
Conversation
…port manifest Store a SHA-256 of each document version's file bytes at write time (content_sha256 on document_versions, nullable for pre-existing rows), refresh it on the in-place rewrite paths (edit accept/reject, version replace, turn-version reuse), and add GET /projects/:projectId/export returning a manifest of every version hash plus the accept/reject trail so an exported file set can be verified against what the workspace held. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Author
|
Withdrawing this for now while I rethink the shape on my side. Will follow up properly. Sorry for the noise. |
Author
|
Reopening — the withdrawal was my mix-up, nothing changed. PR stands as described. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Exports today cannot prove that a document version is the file the workspace actually held. There are no content hashes anywhere in the schema, so once a file leaves Mike there is no way to tell an untouched export from a modified one. This PR stores a SHA-256 of every version's bytes at write time and adds a per-project export manifest, making any export of those files tamper-evident at the source.
Changes
oss-migrations/20260612_document_version_content_sha256.sqlandschema.sql: nullablecontent_sha256 textcolumn ondocument_versions. Existing rows stay unhashed until their bytes are next rewritten.lib/documentVersions.ts: one small helper,contentSha256(bytes), SHA-256 hex overArrayBuffer | ArrayBufferView.chatTools.ts.runEditDocument, and version replace.lib/userDataExport.ts:buildProjectExportManifestfollows the same builder pattern as the account export. Stable field order so manifests diff cleanly.routes/projects.ts:GET /projects/:projectId/export, samecheckProjectAccessgate and Content-Disposition idiom as the user export routes. The manifest carries project id/name, every version'scontent_sha256,sourceprovenance,created_at, and thedocument_editsaccept/reject trail (references only, no edit text).Why
Verification becomes one command:
shasum -a 256 file.docxagainst the manifest. This also seems useful for the local/desktop direction and the questions firms ask before adopting a tool like this ("can you prove what was reviewed and accepted"), and hashes at write time are the cheapest possible foundation for that. Zero behavior change otherwise: no existing endpoint's response changes, the column is nullable, and unhashed legacy rows simply shownullin the manifest.A storage backfill for legacy rows would need to stream every object from S3, so I left it out rather than guess at how you would want to batch it. Happy to follow up with one if useful.
Testing
npm run build --prefix backendpasses (tsc, no errors).Buffer,ArrayBuffer, and offsetUint8Arrayviews (several call sites pass views into larger buffers, e.g. multer'sfile.buffer).backend/, so I did not introduce one for this.I work on Legalise, a UK-side project on the accountability layer; happy to align this manifest with anything you'd rather see.
Andy
🤖 Generated with Claude Code