You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/06/03 01:44:37 UTC

(superset) branch master updated: fix(plugin-chart-ag-grid-table): validate filter values/operators in state converter (#40623)

This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new c54990c861b fix(plugin-chart-ag-grid-table): validate filter values/operators in state converter (#40623)
c54990c861b is described below

commit c54990c861b6d39a539e40fa676e27375910ec35
Author: Evan Rusackas <ev...@preset.io>
AuthorDate: Tue Jun 2 18:44:29 2026 -0700

    fix(plugin-chart-ag-grid-table): validate filter values/operators in state converter (#40623)
    
    Co-authored-by: Claude Code <no...@anthropic.com>
---
 .../src/stateConversion.ts                         | 30 ++++++---
 .../test/stateConversion.test.ts                   | 73 ++++++++++++++++++++++
 2 files changed, 95 insertions(+), 8 deletions(-)

diff --git a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/stateConversion.ts b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/stateConversion.ts
index bc04be64221..0bbbd26b8aa 100644
--- a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/stateConversion.ts
+++ b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/stateConversion.ts
@@ -216,7 +216,13 @@ function convertFilterToSQL(
     if (conditions.length === 0) return null;
     if (conditions.length === 1) return conditions[0];
 
-    return `(${conditions.join(` ${filter.operator} `)})`;
+    // The join operator is interpolated into raw SQL, so only allow the two
+    // boolean connectors AG Grid produces.
+    const joinOperator = String(filter.operator).toUpperCase();
+    if (joinOperator !== 'AND' && joinOperator !== 'OR') {
+      return null;
+    }
+    return `(${conditions.join(` ${joinOperator} `)})`;
   }
 
   // Handle blank/notBlank operators for all filter types
@@ -263,20 +269,26 @@ function convertFilterToSQL(
     filter.filter !== undefined &&
     filter.type
   ) {
+    // Number values are interpolated into the clause without quoting, so they
+    // must be finite numbers. Coerce and skip the filter if it is not numeric.
+    const numericValue = Number(filter.filter);
+    if (!Number.isFinite(numericValue)) {
+      return null;
+    }
     // Map number filter types to SQL operators
     switch (filter.type) {
       case FILTER_OPERATORS.EQUALS:
-        return `${colId} ${SQL_OPERATORS.EQUALS} ${filter.filter}`;
+        return `${colId} ${SQL_OPERATORS.EQUALS} ${numericValue}`;
       case FILTER_OPERATORS.NOT_EQUAL:
-        return `${colId} ${SQL_OPERATORS.NOT_EQUALS} ${filter.filter}`;
+        return `${colId} ${SQL_OPERATORS.NOT_EQUALS} ${numericValue}`;
       case FILTER_OPERATORS.LESS_THAN:
-        return `${colId} ${SQL_OPERATORS.LESS_THAN} ${filter.filter}`;
+        return `${colId} ${SQL_OPERATORS.LESS_THAN} ${numericValue}`;
       case FILTER_OPERATORS.LESS_THAN_OR_EQUAL:
-        return `${colId} ${SQL_OPERATORS.LESS_THAN_OR_EQUAL} ${filter.filter}`;
+        return `${colId} ${SQL_OPERATORS.LESS_THAN_OR_EQUAL} ${numericValue}`;
       case FILTER_OPERATORS.GREATER_THAN:
-        return `${colId} ${SQL_OPERATORS.GREATER_THAN} ${filter.filter}`;
+        return `${colId} ${SQL_OPERATORS.GREATER_THAN} ${numericValue}`;
       case FILTER_OPERATORS.GREATER_THAN_OR_EQUAL:
-        return `${colId} ${SQL_OPERATORS.GREATER_THAN_OR_EQUAL} ${filter.filter}`;
+        return `${colId} ${SQL_OPERATORS.GREATER_THAN_OR_EQUAL} ${numericValue}`;
       default:
         return null;
     }
@@ -314,7 +326,9 @@ export function convertFilterModel(
     return undefined;
   }
 
-  const sqlClauses: Record<string, string> = {};
+  // Null-prototype object: column ids come from the (user-influenced) filter
+  // model and are used as keys here, so avoid prototype-chain keys.
+  const sqlClauses: Record<string, string> = Object.create(null);
 
   Object.entries(filterModel).forEach(([colId, filter]) => {
     const sqlClause = convertFilterToSQL(colId, filter);
diff --git a/superset-frontend/plugins/plugin-chart-ag-grid-table/test/stateConversion.test.ts b/superset-frontend/plugins/plugin-chart-ag-grid-table/test/stateConversion.test.ts
new file mode 100644
index 00000000000..d01c6118c9a
--- /dev/null
+++ b/superset-frontend/plugins/plugin-chart-ag-grid-table/test/stateConversion.test.ts
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { convertFilterModel } from '../src/stateConversion';
+
+describe('convertFilterModel', () => {
+  test('emits a clause for a valid numeric comparison filter', () => {
+    const result = convertFilterModel({
+      revenue: { filterType: 'number', type: 'greaterThan', filter: 100 },
+    } as any);
+
+    expect(result?.sqlClauses?.revenue).toBe('revenue > 100');
+  });
+
+  test('drops a number filter whose value is not numeric', () => {
+    const result = convertFilterModel({
+      revenue: { filterType: 'number', type: 'equals', filter: '1 OR 1=1' },
+    } as any);
+
+    expect(result).toBeUndefined();
+  });
+
+  test('joins conditions with a valid boolean operator', () => {
+    const result = convertFilterModel({
+      revenue: {
+        filterType: 'number',
+        operator: 'AND',
+        condition1: { filterType: 'number', type: 'greaterThan', filter: 1 },
+        condition2: { filterType: 'number', type: 'lessThan', filter: 9 },
+      },
+    } as any);
+
+    expect(result?.sqlClauses?.revenue).toBe('(revenue > 1 AND revenue < 9)');
+  });
+
+  test('drops a compound filter whose join operator is not AND/OR', () => {
+    const result = convertFilterModel({
+      revenue: {
+        filterType: 'number',
+        operator: 'AND 1=1) OR (1=1',
+        condition1: { filterType: 'number', type: 'greaterThan', filter: 1 },
+        condition2: { filterType: 'number', type: 'lessThan', filter: 9 },
+      },
+    } as any);
+
+    expect(result).toBeUndefined();
+  });
+
+  test('stores clauses on a null-prototype map (prototype-safe column ids)', () => {
+    const result = convertFilterModel({
+      constructor: { filterType: 'number', type: 'equals', filter: 5 },
+    } as any);
+
+    // The map has no prototype, so a column id like "constructor" is just data.
+    expect(Object.getPrototypeOf(result?.sqlClauses)).toBeNull();
+    expect(result?.sqlClauses?.constructor).toBe('constructor = 5');
+  });
+});