Skip to content

fix: address security and correctness issues in file persistence (#300)#307

Closed
fuziontech wants to merge 2 commits intomainfrom
feat/file-persistence-fixes
Closed

fix: address security and correctness issues in file persistence (#300)#307
fuziontech wants to merge 2 commits intomainfrom
feat/file-persistence-fixes

Conversation

@fuziontech
Copy link
Member

Summary

Follow-up fixes for #300 (file persistence feature). Addresses the issues identified in review:

  • Path traversal protection: Reject usernames containing /, \, or .. to prevent file-backed DB paths from escaping DataDir
  • Concurrent connection pooling: Add a shared *sql.DB pool per user so multiple client connections reuse the same DuckDB file handle instead of fighting over the write lock
  • Config validation: Warn and disable file_persistence when data_dir is empty, preventing silent fallback to in-memory
  • Directory creation: os.MkdirAll the data directory before opening file-backed DBs

Test plan

  • Path traversal: usernames with /, \, .. are rejected with clear error
  • Pool: concurrent acquireFileDB calls return the same *sql.DB; DB closes after last releaseFileDB
  • Config: file_persistence: true without data_dir produces warning and disables persistence
  • Directory creation: nested non-existent DataDir is created automatically
  • All existing tests pass (go test ./...)

🤖 Generated with Claude Code

robertjbass and others added 2 commits March 9, 2026 23:53
Add a `file_persistence` config option (YAML, env var, CLI flag) that
stores DuckDB data in `<data_dir>/<username>.duckdb` instead of using
per-connection in-memory databases.

When enabled, DuckDB memory-maps the file and serves from RAM — giving
Redis-like performance with disk durability. Data persists across
client disconnects and duckgres restarts.

The default behavior is unchanged: `file_persistence` defaults to false,
so every connection still gets an isolated ephemeral in-memory DuckDB.

Config resolution follows the existing YAML → env → CLI precedence:
- YAML: `file_persistence: true`
- Env: `DUCKGRES_FILE_PERSISTENCE=true`
- CLI: `--file-persistence`
- Reject usernames containing path separators or ".." to prevent path
  traversal when constructing file-backed DB paths
- Add shared *sql.DB pool per user so concurrent connections reuse the
  same DuckDB file handle instead of fighting over the write lock
- Validate that file_persistence requires a non-empty data_dir at config
  resolution time, with a warning if misconfigured
- Create data directory with os.MkdirAll before opening file-backed DBs
- Skip DuckLake detach on cleanup for shared DBs (stays attached for
  pool lifetime)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fuziontech fuziontech closed this Mar 12, 2026
@fuziontech fuziontech deleted the feat/file-persistence-fixes branch March 12, 2026 01:56
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.

2 participants