Skip to content

fix(security): resolve SQL injection risks in PostgreSQL backend - #35

Merged
vistart merged 7 commits into
release/v1.0.0.dev13from
feature/sql-injection-fix
May 1, 2026
Merged

vistart merged 7 commits into
release/v1.0.0.dev13from
feature/sql-injection-fix

Conversation

@vistart

@vistart vistart commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Resolves SQL injection risks in PostgreSQL backend by properly using parameterized queries.

Type of change

  • fix: A bug fix
  • docs: Documentation only changes
  • perf: A code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • chore: Changes to the build process or auxiliary tools
  • ci: Changes to our CI configuration files
  • build: Changes that affect the build system
  • revert: Reverts a previous commit

Breaking Change

  • Yes
  • No

Applicable rhosocial-activerecord Version Range:

=1.0.0.dev13,<1.0.0.dev14

Related Repositories/Packages

Testing

  • I have added new tests to cover my changes.
  • I have updated existing tests to reflect my changes.
  • All existing tests pass.
  • This change has been tested on PostgreSQL 14-17.

Test Plan:
Ran security tests for SQL injection prevention.

Checklist

  • My code follows the project's code style guidelines.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added a Changelog fragment (changelog.d/<issue_number>.<type>.md).
  • I have verified that my changes do not introduce SQL injection vulnerabilities.
  • I have checked for potential performance regressions.

Additional Notes

Commit history since branching from release/v1.0.0.dev13:

  • 4a08618 chore: use git source for rhosocial-activerecord at release/v1.0.0.dev26
  • e7fd370 test: fix and enhance PostgreSQL security tests
  • 3c2b0e2 test: add SQL injection security tests for PostgreSQL fixes
  • 53495b6 fix: resolve parameter loss bug in where_clause
  • d06af9f fix: resolve SQL injection risks in DDL/DML statements

vistart added 5 commits May 1, 2026 15:31
- Fix partial index where_clause to accept ToSQLProtocol for parameterized queries
- Fix CREATE TYPE ENUM values to use _escape_sql_string for escaping
- Fix trigger function name to use format_identifier for proper quoting
- Fix stored procedure names (CREATE/DROP/CALL) to use format_identifier
- Fix extended statistics names to use format_identifier

Resolves: SQL injection vulnerabilities in PostgreSQL backend
The ToSQLProtocol path was collecting parameters but returning hardcoded
empty tuple, causing WHERE clause parameters to be silently dropped.

This commit fixes the return statement to include the collected parameters.
- Add tests for CREATE TYPE ENUM value escaping
- Add tests for trigger function name format_identifier
- Add tests for stored procedure names (CREATE/DROP/CALL)
- Add tests for extended statistics names
- Add tests for partial index WHERE clause ToSQLProtocol support

Resolves: Test coverage for SQL injection fixes in PostgreSQL backend
- Fix method name: format_create_type_enum_statement
- Fix method name: format_call_statement
- Add all_params initialization in format_create_index_pg_statement
- Add tests for ENUM escaping, stored procedures, and partial index WHERE clause
@vistart vistart self-assigned this May 1, 2026
@vistart vistart added the bug Something isn't working label May 1, 2026
@codecov

codecov Bot commented May 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.72%. Comparing base (7c1e57f) to head (031b0b4).
⚠️ Report is 1 commits behind head on release/v1.0.0.dev13.

Additional details and impacted files
@@                   Coverage Diff                    @@
##           release/v1.0.0.dev13      #35      +/-   ##
========================================================
+ Coverage                 68.66%   68.72%   +0.06%     
========================================================
  Files                       230      230              
  Lines                     10049    10054       +5     
  Branches                   1598     1599       +1     
========================================================
+ Hits                       6900     6910      +10     
+ Misses                     2628     2621       -7     
- Partials                    521      523       +2     
Flag Coverage Δ
postgres-18 68.72% <100.00%> (+0.06%) ⬆️
python-3.14 68.72% <100.00%> (+0.06%) ⬆️
unittests 68.72% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

sonarqubecloud Bot commented May 1, 2026

Copy link
Copy Markdown

@vistart
vistart merged commit 6bb7f2a into release/v1.0.0.dev13 May 1, 2026
12 checks passed
@vistart vistart mentioned this pull request May 15, 2026
3 tasks done
vistart added a commit that referenced this pull request May 15, 2026
* fix: resolve SQL injection risks in DDL/DML statements

- Fix partial index where_clause to accept ToSQLProtocol for parameterized queries
- Fix CREATE TYPE ENUM values to use _escape_sql_string for escaping
- Fix trigger function name to use format_identifier for proper quoting
- Fix stored procedure names (CREATE/DROP/CALL) to use format_identifier
- Fix extended statistics names to use format_identifier

Resolves: SQL injection vulnerabilities in PostgreSQL backend

* fix: resolve parameter loss bug in where_clause

The ToSQLProtocol path was collecting parameters but returning hardcoded
empty tuple, causing WHERE clause parameters to be silently dropped.

This commit fixes the return statement to include the collected parameters.

* test: add SQL injection security tests for PostgreSQL fixes

- Add tests for CREATE TYPE ENUM value escaping
- Add tests for trigger function name format_identifier
- Add tests for stored procedure names (CREATE/DROP/CALL)
- Add tests for extended statistics names
- Add tests for partial index WHERE clause ToSQLProtocol support

Resolves: Test coverage for SQL injection fixes in PostgreSQL backend

* test: fix and enhance PostgreSQL security tests

- Fix method name: format_create_type_enum_statement
- Fix method name: format_call_statement
- Add all_params initialization in format_create_index_pg_statement
- Add tests for ENUM escaping, stored procedures, and partial index WHERE clause

* chore: use git source for rhosocial-activerecord at release/v1.0.0.dev26

* test: update test assertions for quoted identifiers

* chore: add changelog fragment for PR #35
@vistart
vistart deleted the feature/sql-injection-fix branch May 30, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant