[Bug] SingleFile (.scdb) mode ignores DatabaseOptions.EncryptionKey, writing data in plaintext - #342
[Bug] SingleFile (.scdb) mode ignores DatabaseOptions.EncryptionKey, writing data in plaintext#342saltus7 wants to merge 2 commits into
Conversation
- Added test.runner config to global.json for MTP-native dotnet test - Build succeeds (291 warnings, non-fatal) - All 2,404 tests pass, 16 skipped, 0 failed
…writing data in plaintext
|
…n fix (#341) Credit @saltus7 (PR #342) for independently root-causing issue #341 and submitting a complete proposed fix (AES-256-GCM at rest on every block I/O path + 12-test regression suite) before v1.9.7 shipped. Adds CONTRIBUTORS.md, CHANGELOG/NuGet-README credit lines and a README pointer, plus a Co-authored-by trailer so the contribution is recorded in git history. Co-authored-by: saltus7 <saltus7@users.noreply.github.com>
|
Thank you so much for this contribution — and sincere apologies for the crossed wires on our side. The short version: your diagnosis was 100% correct, and your PR arrived before we shipped our own fix. We resolved issue #341 with our own implementation in v1.9.7 (commit What you got right:
Credit — we've made it permanent:
Since v1.9.7 already ships the fix and your branch is based on an earlier We'd love to see more contributions from you — thank you for the excellent work. 🙏 |
|
Thank you for the incredibly thoughtful response and for ensuring the credit was preserved in the git history and release notes. I really appreciate the professional handling of the crossed wires! It's great to see the fix shipped in v1.9.7. I'm evaluating SharpCoreDB for a local-first edge-node architecture (which requires strict AES-256-GCM at-rest encryption and single-file deployment), so finding and resolving this was a critical step for my own adoption of the library. I'll hold off on the |
|
Quick follow-up: I've now reviewed the v1.9.7 implementation in detail, and I want to give credit where it's due. My PR handled the happy path — encrypt on write, decrypt on read — but it left several serious gaps that I didn't catch. Your fix addressed all of them:
My submission was a prototype. Yours is production-grade. The attention to edge cases — especially the ones that would have caused silent data corruption rather than loud failures — is exactly what this kind of security-critical path needs. Thanks for taking the time to do it right. Moving forward with my integration on v1.9.7 now. |



Summary
Fixes a critical bug where SingleFile (.scdb) storage mode ignored
DatabaseOptions.EncryptionKey, writing data in plaintext even when encryption was configured.Root Cause
The
SingleFileStorageProvideraccepted the encryption configuration but never instantiatedAesGcmEncryptionor intercepted the I/O paths. Consequently,WriteBlockAsync,ReadBlockAsync,GetReadSpan, andGetReadStreamoperated directly on the rawFileStream, bypassing encryption entirely. (Directory mode was unaffected as it correctly wiredICryptoServiceviaDatabase.Core.cs).Changes
src/SharpCoreDB/DatabaseExtensions.cs: ResolvesICryptoServicefrom DI when encryption is enabled and passes it to the SingleFile provider.src/SharpCoreDB/Storage/SingleFileStorageProvider.cs: WiresAesGcmEncryptioninto the provider and intercepts all block read/write/stream paths to encrypt/decrypt data at rest.tests/SharpCoreDB.Tests/Security/SingleFileEncryptionTests.cs: Adds a comprehensive 12-test regression suite covering plaintext-at-rest, correct-key roundtrip, wrong-key rejection, and file integrity.src/SharpCoreDB/DatabaseOptions.cs,src/SharpCoreDB/SingleFileTable.cs,src/SharpCoreDB/Storage/Scdb/SingleFileDatabase.Batch.cs: (Included from local build/test adjustments).Also included
global.json(root): Addedtest.runnerconfig for MTP-nativedotnet teston .NET 10 SDK. Without this,dotnet testfails witherror Testing with VSTest target is no longer supported.Fixes #341
Verification