Skip to content

Commit af657c6

Browse files
densumeshskeptrunedev
authored andcommitted
security: make the clickhouse analytics query more secure and robust
1 parent bb62d4b commit af657c6

File tree

9 files changed

+835
-211
lines changed

9 files changed

+835
-211
lines changed

clients/trieve-shopify-extension/app/routes/app._dashboard.experimentview.$experimentId.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
5555
alias: "event_count",
5656
})
5757
.from("events")
58-
.join(
58+
.joinOn(
5959
"experiment_user_assignments",
60-
"experiment_user_assignments.user_id = events.user_id",
60+
"experiment_user_assignments.user_id",
61+
"events.user_id",
6162
)
6263
.where({
6364
column: "events.event_name",
@@ -105,9 +106,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
105106
distinct: true,
106107
})
107108
.from("events")
108-
.join(
109+
.joinOn(
109110
"experiment_user_assignments",
110-
"experiment_user_assignments.user_id = events.user_id",
111+
"experiment_user_assignments.user_id",
112+
"events.user_id",
111113
)
112114
.where({
113115
column: "experiment_user_assignments.experiment_id",
@@ -156,9 +158,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
156158
alias: "total_conversion_event_count",
157159
})
158160
.from("events")
159-
.join(
161+
.joinOn(
160162
"experiment_user_assignments",
161-
"experiment_user_assignments.user_id = events.user_id",
163+
"experiment_user_assignments.user_id",
164+
"events.user_id",
162165
)
163166
.where({
164167
column: "experiment_user_assignments.experiment_id",

clients/trieve-shopify-extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"tailwind-merge": "^3.1.0",
5757
"tailwindcss": "^3.4.17",
5858
"trieve-search-component": "0.4.65",
59-
"trieve-ts-sdk": "^0.0.115",
59+
"trieve-ts-sdk": "^0.0.116",
6060
"vite-tsconfig-paths": "^5.0.1"
6161
},
6262
"devDependencies": {

clients/trieve-shopify-extension/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9384,10 +9384,10 @@ trieve-search-component@0.4.65:
93849384
tailwind-merge "^3.0.2"
93859385
trieve-ts-sdk "^0.0.90"
93869386

9387-
trieve-ts-sdk@^0.0.115:
9388-
version "0.0.115"
9389-
resolved "https://registry.yarnpkg.com/trieve-ts-sdk/-/trieve-ts-sdk-0.0.115.tgz#c54b2be29916e087991f413cae9b48c92f7125df"
9390-
integrity sha512-1VkI5GJ0mKEQcRjM1amX62TZvRtuZoB5NfFHba6qpK0JnXtLm7h9O8UtjRliUu2gi35J6zIU49OaYgd/OIVV3w==
9387+
trieve-ts-sdk@^0.0.116:
9388+
version "0.0.116"
9389+
resolved "https://registry.yarnpkg.com/trieve-ts-sdk/-/trieve-ts-sdk-0.0.116.tgz#33942d46b14c5c844b9470fc096abf0abcbb769e"
9390+
integrity sha512-33lTgEBDNnPHdRdEGVIU/o7abwPl1e6EXSVtztrKEnQzvzMpfthJ6MFTOAxEu8PYEmBU6NpBMUn/uq0voNeHkA==
93919391

93929392
trieve-ts-sdk@^0.0.90:
93939393
version "0.0.90"

clients/ts-sdk/openapi.json

Lines changed: 230 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13582,7 +13582,7 @@
1358213582
},
1358313583
"Expression": {
1358413584
"type": "object",
13585-
"description": "Represents a SQL function or expression",
13585+
"description": "Represents a SQL expression with optional alias",
1358613586
"required": [
1358713587
"expression"
1358813588
],
@@ -13592,10 +13592,97 @@
1359213592
"nullable": true
1359313593
},
1359413594
"expression": {
13595-
"type": "string"
13595+
"$ref": "#/components/schemas/ExpressionType"
1359613596
}
1359713597
}
1359813598
},
13599+
"ExpressionType": {
13600+
"oneOf": [
13601+
{
13602+
"type": "object",
13603+
"required": [
13604+
"name",
13605+
"type"
13606+
],
13607+
"properties": {
13608+
"name": {
13609+
"type": "string"
13610+
},
13611+
"type": {
13612+
"type": "string",
13613+
"enum": [
13614+
"column"
13615+
]
13616+
}
13617+
}
13618+
},
13619+
{
13620+
"type": "object",
13621+
"required": [
13622+
"value",
13623+
"type"
13624+
],
13625+
"properties": {
13626+
"type": {
13627+
"type": "string",
13628+
"enum": [
13629+
"literal"
13630+
]
13631+
},
13632+
"value": {
13633+
"$ref": "#/components/schemas/FilterValue"
13634+
}
13635+
}
13636+
},
13637+
{
13638+
"type": "object",
13639+
"required": [
13640+
"name",
13641+
"args",
13642+
"type"
13643+
],
13644+
"properties": {
13645+
"args": {
13646+
"type": "array",
13647+
"items": {
13648+
"$ref": "#/components/schemas/ExpressionType"
13649+
}
13650+
},
13651+
"name": {
13652+
"type": "string"
13653+
},
13654+
"type": {
13655+
"type": "string",
13656+
"enum": [
13657+
"function"
13658+
]
13659+
}
13660+
}
13661+
},
13662+
{
13663+
"type": "object",
13664+
"required": [
13665+
"sql",
13666+
"type"
13667+
],
13668+
"properties": {
13669+
"sql": {
13670+
"type": "string"
13671+
},
13672+
"type": {
13673+
"type": "string",
13674+
"enum": [
13675+
"raw"
13676+
]
13677+
}
13678+
}
13679+
}
13680+
],
13681+
"description": "Structured expression type",
13682+
"discriminator": {
13683+
"propertyName": "type"
13684+
}
13685+
},
1359913686
"ExtendedOrganizationUsageCount": {
1360013687
"type": "object",
1360113688
"required": [
@@ -14933,7 +15020,11 @@
1493315020
}
1493415021
},
1493515022
"having": {
14936-
"type": "string",
15023+
"allOf": [
15024+
{
15025+
"$ref": "#/components/schemas/HavingCondition"
15026+
}
15027+
],
1493715028
"nullable": true
1493815029
}
1493915030
}
@@ -15096,6 +15187,86 @@
1509615187
}
1509715188
}
1509815189
},
15190+
"HavingCondition": {
15191+
"oneOf": [
15192+
{
15193+
"type": "object",
15194+
"required": [
15195+
"function",
15196+
"column",
15197+
"operator",
15198+
"value",
15199+
"type"
15200+
],
15201+
"properties": {
15202+
"column": {
15203+
"type": "string"
15204+
},
15205+
"function": {
15206+
"$ref": "#/components/schemas/AggregationType"
15207+
},
15208+
"operator": {
15209+
"$ref": "#/components/schemas/FilterOperator"
15210+
},
15211+
"type": {
15212+
"type": "string",
15213+
"enum": [
15214+
"aggregate"
15215+
]
15216+
},
15217+
"value": {
15218+
"$ref": "#/components/schemas/FilterValue"
15219+
}
15220+
}
15221+
},
15222+
{
15223+
"type": "object",
15224+
"required": [
15225+
"conditions",
15226+
"type"
15227+
],
15228+
"properties": {
15229+
"conditions": {
15230+
"type": "array",
15231+
"items": {
15232+
"$ref": "#/components/schemas/HavingCondition"
15233+
}
15234+
},
15235+
"type": {
15236+
"type": "string",
15237+
"enum": [
15238+
"and"
15239+
]
15240+
}
15241+
}
15242+
},
15243+
{
15244+
"type": "object",
15245+
"required": [
15246+
"conditions",
15247+
"type"
15248+
],
15249+
"properties": {
15250+
"conditions": {
15251+
"type": "array",
15252+
"items": {
15253+
"$ref": "#/components/schemas/HavingCondition"
15254+
}
15255+
},
15256+
"type": {
15257+
"type": "string",
15258+
"enum": [
15259+
"or"
15260+
]
15261+
}
15262+
}
15263+
}
15264+
],
15265+
"description": "Structured HAVING condition",
15266+
"discriminator": {
15267+
"propertyName": "type"
15268+
}
15269+
},
1509915270
"HeadQueries": {
1510015271
"type": "object",
1510115272
"required": [
@@ -15445,12 +15616,15 @@
1544515616
},
1544615617
"JoinClause": {
1544715618
"type": "object",
15448-
"description": "Represents a join condition between tables",
15619+
"description": "Represents a join between tables",
1544915620
"required": [
1545015621
"table",
15451-
"on_clause"
15622+
"condition"
1545215623
],
1545315624
"properties": {
15625+
"condition": {
15626+
"$ref": "#/components/schemas/JoinCondition"
15627+
},
1545415628
"join_type": {
1545515629
"allOf": [
1545615630
{
@@ -15459,14 +15633,62 @@
1545915633
],
1546015634
"nullable": true
1546115635
},
15462-
"on_clause": {
15463-
"type": "string"
15464-
},
1546515636
"table": {
1546615637
"$ref": "#/components/schemas/TableName"
1546715638
}
1546815639
}
1546915640
},
15641+
"JoinCondition": {
15642+
"oneOf": [
15643+
{
15644+
"type": "object",
15645+
"required": [
15646+
"left_column",
15647+
"right_column",
15648+
"type"
15649+
],
15650+
"properties": {
15651+
"left_column": {
15652+
"type": "string"
15653+
},
15654+
"right_column": {
15655+
"type": "string"
15656+
},
15657+
"type": {
15658+
"type": "string",
15659+
"enum": [
15660+
"column_equals"
15661+
]
15662+
}
15663+
}
15664+
},
15665+
{
15666+
"type": "object",
15667+
"required": [
15668+
"columns",
15669+
"type"
15670+
],
15671+
"properties": {
15672+
"columns": {
15673+
"type": "array",
15674+
"items": {
15675+
"type": "string"
15676+
}
15677+
},
15678+
"type": {
15679+
"type": "string",
15680+
"enum": [
15681+
"using"
15682+
]
15683+
}
15684+
}
15685+
}
15686+
],
15687+
"description": "Structured join condition instead of raw SQL",
15688+
"discriminator": {
15689+
"propertyName": "type"
15690+
}
15691+
},
1547015692
"JoinType": {
1547115693
"type": "string",
1547215694
"description": "Represents the type of join between tables",

clients/ts-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"files": [
1818
"dist"
1919
],
20-
"version": "0.0.115",
20+
"version": "0.0.116",
2121
"license": "MIT",
2222
"scripts": {
2323
"lint": "eslint 'src/**/*.ts'",

0 commit comments

Comments
 (0)