Bound restore archives and validate attachment integrity - #42
Merged
Void-n-Null merged 10 commits intoAug 27, 2026
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens dump/restore and attachment handling so restores from malformed or untrusted archives are bounded, traversal-safe, and integrity-checked before they can replace live state. It also tightens attachment metadata invariants across both the Rust storage layer and the SQLite schema.
Changes:
- Enforce canonical lowercase SHA-256 attachment addresses at storage, restore, and DB schema boundaries.
- Add restore-time limits and validations (entry types, counts, sizes, decompression bounds) plus staged SQLite + attachment integrity checks before installation.
- Introduce migration
043_attachment_integrityand update tests to use real content-addressed hashes.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/storage.rs | Adds valid_sha256 and enforces hash validation before building attachment/thumb paths (plus traversal test). |
| src/mcp/tools.rs | Updates MCP-related tests to use real SHA-256 hashes for attachments. |
| src/dump.rs | Implements bounded archive inspection/extraction, staged DB+blob integrity validation, restore locking, and rollback/transactional installation. |
| src/db/queries/users.rs | Adjusts test SQL to insert a valid attachment SHA. |
| src/db/queries/search.rs | Updates tests to seed attachments with valid SHA-256 hashes. |
| src/db/queries/comments.rs | Updates attachment test to use a valid SHA-256 hash. |
| src/db/queries/attachments.rs | Refactors tests to consistently generate valid hashes; adds test asserting invalid hash/mime rejection. |
| src/db/migrate.rs | Registers migration 43 and marks it as FK-rebuild-sensitive. |
| migrations/043_attachment_integrity.sql | Rebuilds attachments with CHECK constraints for sha256/mime/size and restores FTS triggers. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
mjc
force-pushed
the
security/restore-validation
branch
from
August 26, 2026 16:28
f4b85f9 to
4dfc673
Compare
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
Harden restore against malformed or untrusted dump archives while preserving normal dump/restore behavior.
The branch-added tests cover compressed expansion bombs, oversized entries, excessive entry counts, duplicate control entries, traversal attempts, legacy schema compatibility, invalid attachment metadata, blob hash and MIME mismatches, missing blobs, symlink-safe staging, concurrent restore locking, rollback behavior, and successful dump/restore round trips.