Skip to content

fix(compaction,database): escape SQL interpolations in SET memory_limit and ORDER BY (#289, #290)#378

Merged
xe-nvdk merged 2 commits intomainfrom
fix/compaction-sql-injection
Apr 9, 2026
Merged

fix(compaction,database): escape SQL interpolations in SET memory_limit and ORDER BY (#289, #290)#378
xe-nvdk merged 2 commits intomainfrom
fix/compaction-sql-injection

Conversation

@xe-nvdk
Copy link
Copy Markdown
Member

@xe-nvdk xe-nvdk commented Apr 9, 2026

Summary

Test plan

  • go build ./internal/... passes
  • go test ./internal/compaction/... passes
  • go test ./internal/database/... passes
  • Post-implementation security review: no bypass vectors, all other SET commands verified safe

Closes #289
Closes #290

…it and ORDER BY (#289, #290)

Two SQL injection vulnerabilities fixed:

1. SET memory_limit in duckdb.go and subprocess.go interpolated the
   configured value without escaping single quotes. Applied
   escapeSQLString() in duckdb.go and inline single-quote doubling in
   subprocess.go (different package, avoids cross-package dependency).

2. buildOrderByClause in job.go wrapped sort key names in double quotes
   but did not escape internal double quotes, allowing identifier
   breakout. Added strings.ReplaceAll(key, "\"", "\"\"") before quoting,
   matching the pattern already used in dedup.go for tag columns.

Config validation regex (memoryLimitRe) provides defense-in-depth at
load time, but the SQL escaping is now a failsafe at the point of use.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses two SQL injection vulnerabilities: one in the DuckDB memory limit configuration and another in the compaction ORDER BY clause. The changes implement proper SQL escaping for memory limit values and sort key identifiers. I have no further feedback, as the reviewer's suggestion to centralize the escaping logic is a valid improvement for maintainability and consistency across the codebase.

Comment thread internal/compaction/subprocess.go Outdated
…review

Moved inline single-quote escaping in subprocess.go to a dedicated
escapeSQLString() function in job.go (alongside the existing
escapeSQLPath helper), matching the pattern in database/duckdb.go.
@xe-nvdk xe-nvdk merged commit 93e54e2 into main Apr 9, 2026
6 checks passed
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.

high(compaction): Sort key names not escaped in buildOrderByClause high(compaction): SQL injection in DuckDB SET memory_limit

1 participant