fix(security): prevent SQL injection in PostgreSQL plugin when prepared statements disabled (GHSA-vf2m-c985-hgmh)#41930
fix(security): prevent SQL injection in PostgreSQL plugin when prepared statements disabled (GHSA-vf2m-c985-hgmh)#41930subrata71 wants to merge 2 commits into
Conversation
Adds tests to verify SQL injection is prevented when prepared statements are disabled but query contains mustache bindings (user inputs). Also verifies backward compatibility for static queries without bindings.
…A-vf2m-c985-hgmh) When prepared statements are disabled but the query contains mustache bindings (user-supplied widget inputs), automatically upgrade to prepared statement mode. This prevents SQL injection via string interpolation of untrusted inputs into raw SQL. Static queries without bindings (DDL, admin commands) continue to execute as raw statements for backward compatibility. Root cause: prepareConfigurationsForExecution() performs plain string interpolation of mustache bindings, allowing injection payloads like "' OR '1'='1" to break out of WHERE clauses when executed via Statement.execute().
Walkthrough
Postgres SQL Injection Guard
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
This PR addresses a security vulnerability reported via GitHub Security Advisory.
Advisory: GHSA-vf2m-c985-hgmh
Severity: Critical (CVSS: 9.9)
Type: CWE-89 SQL Injection, CWE-20 Improper Input Validation
Root Cause
When prepared statements are disabled (
isPreparedStatement = false) in the PostgreSQL plugin, user-supplied widget inputs are string-interpolated into the SQL query body via Appsmith's mustache template engine (prepareConfigurationsForExecution). The resulting SQL is then executed viaStatement.execute(query)without parameterization.An attacker can inject arbitrary SQL through widget inputs (e.g.,
' OR '1'='1) to bypass WHERE clauses, exfiltrate data, or modify the database.Fix
When
isPreparedStatementisfalsebut the query contains mustache bindings (user inputs), the plugin now automatically upgrades to prepared statement mode. This ensures:The change is minimal (4 lines of logic) and moves the
extractMustacheKeysInOrdercall before the prepared-statement check, adding&& mustacheKeysInOrder.isEmpty()to the condition.Testing
Notes
This PR was created by the GHSA Fix MVP agent. Please review carefully before merging.
The same vulnerability pattern exists in the MySQL and MSSQL plugins, which should be addressed in follow-up PRs.
/ok-to-test tags="@tag.All"
Caution
🔴 🔴 🔴 Some tests have failed.
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/28336438067
Commit: b0b5bd7
Cypress dashboard.
Tags: @tag.All
Spec:
The following are new failures, please fix them before merging the PR:
- cypress/e2e/Regression/Apps/CommunityIssues_Spec.ts
- cypress/e2e/Regression/ClientSide/BugTests/SelectWidget_Bug9334_Spec.ts
- cypress/e2e/Regression/ClientSide/JSObject/JSObject_Tests_spec.ts
- cypress/e2e/Regression/ClientSide/OneClickBinding/JSEnabledByDefaultExperiment_spec.ts
- cypress/e2e/Regression/ClientSide/OneClickBinding/JSONFormWidget/ConnectToWidget_spec.ts
- cypress/e2e/Regression/ClientSide/OneClickBinding/JSONFormWidget/JSONForm_postgres_spec.ts
- cypress/e2e/Regression/ClientSide/OneClickBinding/MultiSelectWidget/MultiSelect_postgres_spec.ts
- cypress/e2e/Regression/ClientSide/OneClickBinding/SelectWidget/postgres_spec.ts
- cypress/e2e/Regression/ClientSide/OneClickBinding/TableWidget/Table_postgres_spec.ts
- cypress/e2e/Regression/ClientSide/Widgets/Multiselect/MultiSelect4_spec.js
- cypress/e2e/Regression/ClientSide/Widgets/Select/Select3_Spec.ts
- cypress/e2e/Regression/ClientSide/Widgets/Select/Select_spec.js
- cypress/e2e/Regression/ClientSide/Widgets/TableV2/Table_InfiniteScroll_spec.ts
- cypress/e2e/Regression/ClientSide/Widgets/TableV2/columnTypes/Select1_spec.ts
- cypress/e2e/Regression/ServerSide/GenerateCRUD/Postgres1_Spec.ts
- cypress/e2e/Regression/ServerSide/GenerateCRUD/Postgres2_Spec.ts
- cypress/e2e/Regression/ServerSide/Params/ExecutionParams_spec.js
- cypress/e2e/Regression/ServerSide/Postgres_DataTypes/Array_Spec.ts
- cypress/e2e/Regression/ServerSide/Postgres_DataTypes/DateTime_Spec.ts
- cypress/e2e/Regression/ServerSide/Postgres_DataTypes/Json_Spec.ts
- cypress/e2e/Regression/ServerSide/QueryPane/QueryPane_Postgres_Spec.js
List of identified flaky tests.Sun, 28 Jun 2026 23:24:19 UTC
Summary by CodeRabbit
Bug Fixes
Tests