Skip to content

Replace string concatenation with parameterized queries for hash filtering#247

Merged
bertt merged 4 commits intomd5_implementationfrom
copilot/sub-pr-244
Feb 5, 2026
Merged

Replace string concatenation with parameterized queries for hash filtering#247
bertt merged 4 commits intomd5_implementationfrom
copilot/sub-pr-244

Conversation

Copy link
Contributor

Copilot AI commented Feb 5, 2026

Building IN clauses via string concatenation of MD5 hashes creates SQL injection risk and degrades performance with large hash lists (up to 1000+ items per zoom level).

Changes

  • Hash filtering now uses PostgreSQL array operators: = ANY(@hashes) for inclusion, != ALL(@excludeHashes) for exclusion
  • Refactored query construction: GetWhere no longer handles hash exclusion; moved to caller sites with proper parameterization
  • Connection management hardening: Added try-finally blocks to ensure cleanup on exception paths

Before/After

// Before: String concatenation builds long SQL strings
var hashList = string.Join(",", hashes.Select(h => $"'{h}'"));
var query = $"WHERE MD5(...) IN ({hashList})";

// After: Parameterized with array operator
var query = "WHERE MD5(...) = ANY(@hashes)";
cmd.Parameters.AddWithValue("hashes", hashes.ToArray());

Affected methods: FilterHashesByEnvelope, GetGeometriesBoundingBox, GetGeometrySubset, CountFeaturesInBox


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits February 5, 2026 08:21
…rator

Co-authored-by: bertt <538812+bertt@users.noreply.github.com>
Co-authored-by: bertt <538812+bertt@users.noreply.github.com>
Co-authored-by: bertt <538812+bertt@users.noreply.github.com>
@bertt bertt marked this pull request as ready for review February 5, 2026 08:25
Copilot AI changed the title [WIP] Update size-based geometry prioritization for tile generation Replace string concatenation with parameterized queries for hash filtering Feb 5, 2026
Copilot AI requested a review from bertt February 5, 2026 08:28
@bertt bertt merged commit d082ce3 into md5_implementation Feb 5, 2026
2 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.

2 participants