Skip to content

fix(server): prevent SQL injection in UQI filter service projection and sortBy columns#41594

Open
subrata71 wants to merge 2 commits intoreleasefrom
fix/security-sql-injection-filter-service-GHSA-7634
Open

fix(server): prevent SQL injection in UQI filter service projection and sortBy columns#41594
subrata71 wants to merge 2 commits intoreleasefrom
fix/security-sql-injection-filter-service-GHSA-7634

Conversation

@subrata71
Copy link
Collaborator

@subrata71 subrata71 commented Mar 6, 2026

Description

TL;DR: Fix a High-severity SQL injection vulnerability (GHSA-7634-7vm9-xg5q, CVSS 7.7) in FilterDataServiceCE where unsanitized projection and sortBy column names allow arbitrary SQL injection into the H2 in-memory database, enabling server-side file reads via FILE_READ() and cross-user data exposure.

Root Cause

addProjectionCondition() and addSortCondition() in FilterDataServiceCE construct SQL queries by wrapping user-supplied column names in backticks without escaping backtick characters within the input. An authenticated attacker with developer-level workspace access can break out of the backtick quoting and inject arbitrary SQL expressions into the H2 in-memory database.

The WHERE clause was already protected via schema validation (validConditionList()), but this same validation was never applied to projection or sortBy column names — an inconsistency that this fix addresses.

Fix (Defense in Depth — 3 Layers)

  1. Schema validation (primary fix): Added validateProjectionColumns() and validateSortByColumns() methods that whitelist column names against the data schema before any SQL is constructed. This eliminates the entire class of identifier injection — any column name not present in the actual data is rejected with an AppsmithPluginException.

  2. Backtick escaping (defense in depth): Added escapeBacktickIdentifier() that escapes backtick characters (```) in addProjectionCondition and addSortCondition, preventing breakout even if Layer 1 were bypassed.

  3. Schema generation hardening: Extended the existing quote rejection in generateSchema() to also reject backtick characters in data column names, preventing the attack character from entering the system via the data source itself.

Affected Plugins

  • Google Sheets (RowsGetMethod) — uses both projection and sortBy from formData
  • Amazon S3 (AmazonS3Plugin) — uses sortBy from formData (projection is null)

Test Coverage

Added 8 new unit tests covering:

  • Invalid column names in projection and sortBy (rejected)
  • SQL injection payloads via backtick breakout in projection and sortBy (rejected)
  • SQL expression injection via projection (rejected)
  • Backtick characters in data column names via schema generation (rejected)
  • Valid projection and sortBy still work correctly (regression tests)

All 29 tests pass (21 existing + 8 new).

Fixes https://github.com/appsmithorg/appsmith/security/advisories/GHSA-7634-7vm9-xg5q
Fixes https://linear.app/appsmith/issue/APP-14992/bug-prevent-sql-injection-in-uqi-filter-service-projection-and-sortby

Automation

/ok-to-test tags="@tag.All"

🔍 Cypress test results

Important

🟣 🟣 🟣 Your tests are running.
Tests running at: https://github.com/appsmithorg/appsmith/actions/runs/22853341442
Commit: 75ed724
Workflow: PR Automation test suite
Tags: @tag.All
Spec: ``


Mon, 09 Mar 2026 12:26:01 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • Bug Fixes

    • Pre-validate projection and sort inputs against generated schema to catch invalid columns early.
    • Reject column names containing backticks and consistently quote identifiers to prevent injection.
    • Ensure temporary resources are always cleaned up after queries and improve error messages for invalid query configs.
  • Tests

    • Expanded coverage for projection/sort validation, backtick and SQL-injection protection, sort-order errors, and cleanup behavior.

…nd sortBy columns

Validate projection and sortBy column names against the data schema before
SQL construction, matching the existing WHERE clause validation pattern.
Also escape backtick characters in identifiers as defense-in-depth and
reject backticks in column names during schema generation.
@subrata71 subrata71 self-assigned this Mar 6, 2026
@subrata71 subrata71 added the ok-to-test Required label for CI label Mar 6, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 32d70c99-82e5-4874-9425-4e9d13142f3d

📥 Commits

Reviewing files that changed from the base of the PR and between 0575a8f and 75ed724.

📒 Files selected for processing (2)
  • app/server/appsmith-interfaces/src/main/java/com/appsmith/external/services/ce/FilterDataServiceCE.java
  • app/server/appsmith-interfaces/src/test/java/com/appsmith/external/services/FilterDataServiceTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-interfaces/src/test/java/com/appsmith/external/services/FilterDataServiceTest.java

Walkthrough

Adds pre-validation for projection and sort-by inputs, escapes backtick-quoted identifiers in SQL generation, moves data lifecycle into a guarded block for cleanup, and rejects backticks in generated schema column names. Tests expanded to cover projection/sort validation and injection protections.

Changes

Cohort / File(s) Summary
Validation & SQL Safety
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/services/ce/FilterDataServiceCE.java
Added validateProjectionColumns and validateSortByColumns; call these before data insertion/filtering. Introduced escapeBacktickIdentifier and applied it in projection/sort clause construction (addProjectionCondition, addSortCondition). Moved table creation/insertion/query/drop into a guarded try/finally to ensure cleanup. generateSchema now rejects column names containing backticks (throws PLUGIN_EXECUTE_ARGUMENT_ERROR).
Test Coverage
app/server/appsmith-interfaces/src/test/java/com/appsmith/external/services/FilterDataServiceTest.java
Added multiple tests (projection/sort invalid names, backtick injection, SQL-expression injection, null/invalid sort order, schema backtick rejection, valid projection/sort, and table-leak check). Introduced SIMPLE_DATA test constant and expanded assertions around error conditions and cleanup.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

Backticks blocked, projections checked,
Sorts are valid, tables decked,
Cleanup runs in final lines,
Safe queries now draw the signs,
Tests applaud the guarded steps. 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 19.05% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically identifies the security fix: preventing SQL injection in the filter service's projection and sortBy functionality.
Description check ✅ Passed The description is comprehensive, covering root cause, three-layer defense strategy, affected plugins, test coverage, and security advisory references. However, the required 'Fixes #Issue Number' section references an external GitHub advisory URL rather than a traditional issue number.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/security-sql-injection-filter-service-GHSA-7634

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@app/server/appsmith-interfaces/src/main/java/com/appsmith/external/services/ce/FilterDataServiceCE.java`:
- Around line 296-308: The validateSortByColumns method currently only checks
column names; update it to also validate the sort order (SORT_BY_TYPE_KEY) in
the same loop: for each sortCondition in validateSortByColumns (used with
isSortConditionEmpty), check that sortCondition.get(SORT_BY_TYPE_KEY) is not
null/blank and equals one of the allowed values (e.g., "ASC" or "DESC",
case-insensitive) before returning, and if invalid or missing throw an
AppsmithPluginException with AppsmithPluginError.PLUGIN_EXECUTE_ARGUMENT_ERROR
and a clear message including the columnName and the bad/missing order; this
prevents addSortCondition from calling
sortCondition.get(SORT_BY_TYPE_KEY).toUpperCase() on null and centralizes
validation.
- Around line 165-166: Validation of projection/sort columns is performed after
the temp table is created/filled causing leaked tables on validation failure;
move the calls to validateProjectionColumns(...) and validateSortByColumns(...)
to occur before generateTable(...) and insertAllData(...) inside filterDataNew,
and ensure dropTable(...) is executed in a finally block so the temp table is
always removed even on exceptions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 351668b8-34d6-4700-b40e-dcb99b54dfcd

📥 Commits

Reviewing files that changed from the base of the PR and between d18802b and 0575a8f.

📒 Files selected for processing (2)
  • app/server/appsmith-interfaces/src/main/java/com/appsmith/external/services/ce/FilterDataServiceCE.java
  • app/server/appsmith-interfaces/src/test/java/com/appsmith/external/services/FilterDataServiceTest.java

@github-actions
Copy link

github-actions bot commented Mar 6, 2026

Failed server tests

  • com.appsmith.server.git.ServerSchemaMigrationEnforcerTest#saveGitRepo_ImportAndThenExport_diffOccurs

@linear
Copy link

linear bot commented Mar 9, 2026

@subrata71 subrata71 requested a review from sondermanish March 9, 2026 07:07
… creation, add try/finally cleanup, validate sort order

- Move validateProjectionColumns/validateSortByColumns into filterDataNew()
  before generateTable() so invalid input is rejected before the H2 temp
  table is created, preventing table leaks on validation failure.
- Wrap table operations in try/finally to guarantee dropTable() runs even
  if insertAllData or executeFilterQueryNew throws.
- Add sort order validation in validateSortByColumns to reject null/blank
  and invalid sort types early, preventing NPE in addSortCondition.
- Add tests for null sort order, invalid sort order, and table leak prevention.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant