Skip to content

Commit 7a34786

Browse files
committed
cleanup: sql
1 parent 4e7998b commit 7a34786

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

apps/api/src/routes/custom-sql.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,22 @@ const FORBIDDEN_OPERATIONS = [
114114
'TRIGGER',
115115
'EVENT',
116116
'ROUTINE',
117+
// ClickHouse-specific dangerous functions
118+
'HOSTNAME',
119+
'FQDN',
120+
'VERSION',
121+
'UPTIME',
122+
'GETOSKERNEL',
123+
'GETCPUCOUNT',
124+
'GETMEMORYSIZE',
125+
'READFILE',
126+
'WRITEFILE',
127+
'FILESYSTEM',
128+
'DICTGET',
129+
'REMOTE',
130+
'CLUSTER',
131+
'SHARD',
132+
'REPLICA',
117133
];
118134

119135
const FORBIDDEN_PATTERNS = [
@@ -129,6 +145,20 @@ const FORBIDDEN_PATTERNS = [
129145
/\bINTO\s+(?:OUTFILE|DUMPFILE)\b/gi,
130146
/\bEXTRACTVALUE\s*\(/gi,
131147
/\bUPDATEXML\s*\(/gi,
148+
// ClickHouse system table access patterns
149+
/\bFROM\s+system\./gi,
150+
/\bJOIN\s+system\./gi,
151+
/\binformation_schema\./gi,
152+
/\bdefault\./gi,
153+
// Dangerous ClickHouse functions
154+
/\burl\s*\(/gi,
155+
/\bfile\s*\(/gi,
156+
/\bs3\s*\(/gi,
157+
/\bhdfs\s*\(/gi,
158+
/\bmysql\s*\(/gi,
159+
/\bpostgresql\s*\(/gi,
160+
/\bremote\s*\(/gi,
161+
/\bcluster\s*\(/gi,
132162
];
133163

134164
const ALLOWED_TABLES = [
@@ -595,7 +625,6 @@ export const customSQL = new Elysia({ prefix: '/v1/custom-sql' })
595625
executionTime: result.execution_time || null,
596626
rowsRead: result.rows_read || null,
597627
clientId: body.clientId,
598-
apiKeyId: apiKey.id,
599628
},
600629
};
601630
} catch (error) {
@@ -614,7 +643,7 @@ export const customSQL = new Elysia({ prefix: '/v1/custom-sql' })
614643
return {
615644
success: false,
616645
error:
617-
error instanceof Error ? error.message : 'Query execution failed',
646+
'Query execution failed. Please check your query syntax and try again.',
618647
code: 'EXECUTION_ERROR',
619648
};
620649
}

0 commit comments

Comments
 (0)