Skip to content

[Bug] SingleFile (.scdb) mode ignores DatabaseOptions.EncryptionKey, writing data in plaintext - #342

Open
saltus7 wants to merge 2 commits into
MPCoreDeveloper:masterfrom
saltus7:master
Open

[Bug] SingleFile (.scdb) mode ignores DatabaseOptions.EncryptionKey, writing data in plaintext#342
saltus7 wants to merge 2 commits into
MPCoreDeveloper:masterfrom
saltus7:master

Conversation

@saltus7

@saltus7 saltus7 commented Aug 29, 2026

Copy link
Copy Markdown

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 SingleFileStorageProvider accepted the encryption configuration but never instantiated AesGcmEncryption or intercepted the I/O paths. Consequently, WriteBlockAsync, ReadBlockAsync, GetReadSpan, and GetReadStream operated directly on the raw FileStream, bypassing encryption entirely. (Directory mode was unaffected as it correctly wired ICryptoService via Database.Core.cs).

Changes

  • src/SharpCoreDB/DatabaseExtensions.cs: Resolves ICryptoService from DI when encryption is enabled and passes it to the SingleFile provider.
  • src/SharpCoreDB/Storage/SingleFileStorageProvider.cs: Wires AesGcmEncryption into 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): Added test.runner config for MTP-native dotnet test on .NET 10 SDK. Without this, dotnet test fails with error Testing with VSTest target is no longer supported.

Fixes #341

Verification

  • Build succeeds (warnings are non-fatal)
  • Full test suite passes: 2,416 passed, 16 skipped, 0 failed (Total: 2,432)

scdb-dev added 2 commits August 28, 2026 22:00
- 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
@sonarqubecloud

Copy link
Copy Markdown

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.

[Bug] SingleFile (.scdb) mode ignores DatabaseOptions.EncryptionKey, writing data in plaintext

1 participant