Skip to content

Commit 40e2c5e

Browse files
committed
remove validate query checks
1 parent 843dbc2 commit 40e2c5e

File tree

2 files changed

+0
-71
lines changed

2 files changed

+0
-71
lines changed

internal/common/utils.go

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package common
22

33
import (
4-
"fmt"
54
"math/big"
6-
"regexp"
7-
"strings"
85
)
96

107
func SliceToChunks[T any](values []T, chunkSize int) [][]T {
@@ -22,68 +19,6 @@ func SliceToChunks[T any](values []T, chunkSize int) [][]T {
2219
return chunks
2320
}
2421

25-
var allowedFunctions = map[string]struct{}{
26-
"sum": {},
27-
"count": {},
28-
"countdistinct": {},
29-
"avg": {},
30-
"max": {},
31-
"min": {},
32-
"reinterpretasuint256": {},
33-
"reverse": {},
34-
"unhex": {},
35-
"substring": {},
36-
"length": {},
37-
"touint256": {},
38-
"if": {},
39-
"tostartofmonth": {},
40-
"tostartofday": {},
41-
"tostartofhour": {},
42-
"tostartofminute": {},
43-
"todate": {},
44-
"todatetime": {},
45-
"concat": {},
46-
"in": {},
47-
"and": {},
48-
"or": {},
49-
}
50-
51-
var disallowedPatterns = []string{
52-
`(?i)\b(INSERT|DELETE|UPDATE|DROP|CREATE|ALTER|TRUNCATE|EXEC|;|--)`,
53-
}
54-
55-
// ValidateQuery checks the query for disallowed patterns and ensures only allowed functions are used.
56-
func ValidateQuery(query string) error {
57-
// Check for disallowed patterns
58-
for _, pattern := range disallowedPatterns {
59-
matched, err := regexp.MatchString(pattern, query)
60-
if err != nil {
61-
return fmt.Errorf("error checking disallowed patterns: %v", err)
62-
}
63-
if matched {
64-
return fmt.Errorf("query contains disallowed keywords or patterns")
65-
}
66-
}
67-
68-
// Ensure the query is a SELECT statement
69-
trimmedQuery := strings.TrimSpace(strings.ToUpper(query))
70-
if !strings.HasPrefix(trimmedQuery, "SELECT") {
71-
return fmt.Errorf("only SELECT queries are allowed")
72-
}
73-
74-
// Extract function names and validate them
75-
functionPattern := regexp.MustCompile(`(?i)(\b\w+\b)\s*\(`)
76-
matches := functionPattern.FindAllStringSubmatch(query, -1)
77-
for _, match := range matches {
78-
funcName := match[1]
79-
if _, ok := allowedFunctions[strings.ToLower(funcName)]; !ok {
80-
return fmt.Errorf("function '%s' is not allowed", funcName)
81-
}
82-
}
83-
84-
return nil
85-
}
86-
8722
func ConvertBigNumbersToString(data interface{}) interface{} {
8823
switch v := data.(type) {
8924
case map[string]interface{}:

internal/storage/clickhouse.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,6 @@ func (c *ClickHouseConnector) GetAggregations(table string, qf QueryFilter) (Que
473473
// Use the new query building logic
474474
query := c.buildQuery(table, selectColumns, qf)
475475

476-
if err := common.ValidateQuery(query); err != nil {
477-
return QueryResult[interface{}]{}, err
478-
}
479476
// Execute the query
480477
rows, err := c.conn.Query(context.Background(), query)
481478
if err != nil {
@@ -528,9 +525,6 @@ func (c *ClickHouseConnector) GetAggregations(table string, qf QueryFilter) (Que
528525
func executeQuery[T any](c *ClickHouseConnector, table, columns string, qf QueryFilter, scanFunc func(driver.Rows) (T, error)) (QueryResult[T], error) {
529526
query := c.buildQuery(table, columns, qf)
530527

531-
if err := common.ValidateQuery(query); err != nil {
532-
return QueryResult[T]{}, err
533-
}
534528
rows, err := c.conn.Query(context.Background(), query)
535529
if err != nil {
536530
return QueryResult[T]{}, err

0 commit comments

Comments
 (0)