Commit 689f393
authored
Validate duckgres.query_source against its allowed values (#948)
The duckgres.query_source session GUC is a billing dimension: it flows
verbatim from the session into the compute-usage bucket key
(duckgres_org_compute_usage.query_source) and onward into the billing
pull API. It previously accepted ANY string on every set path (simple
SET, split multi-statement batches, extended-protocol Parse, and the
-c startup option), handing clients unbounded cardinality and arbitrary
junk (10KB strings, control characters) in the billing table and its
exports.
Now the value is a closed enum, validated once at the transpiler
interception (transform.NormalizeQuerySource) so every SQL path rejects
an invalid value with SQLSTATE 22023 before anything is stored on the
session: 'invalid value for "duckgres.query_source": must be
"standard" or "endpoints"'. Matching is case-insensitive and
normalized to lowercase; empty resets to the default (unchanged
semantics); a SET whose value is not a single simple constant/identifier
is rejected instead of silently resetting. An invalid startup option
rejects the connection with FATAL 22023, matching the duckgres.worker_*
startup options. The rejection message deliberately does not echo the
offending value (it is arbitrary client input and error text lands in
logs and the admin recent-errors ring).
Defense in depth: server.ConnectionBilling clamps a non-canonical value
to "standard" at the metering boundary (warn log, value length only),
so a future validation bypass still cannot write junk into the billing
bucket key.1 parent ad379d9 commit 689f393
10 files changed
Lines changed: 450 additions & 35 deletions
File tree
- docs/design
- server
- tests/mw-dev/e2e
- transpiler
- transform
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
470 | 470 | | |
471 | 471 | | |
472 | 472 | | |
473 | | - | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
474 | 482 | | |
475 | 483 | | |
476 | 484 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
47 | 57 | | |
48 | 58 | | |
49 | 59 | | |
| |||
167 | 177 | | |
168 | 178 | | |
169 | 179 | | |
170 | | - | |
| 180 | + | |
| 181 | + | |
171 | 182 | | |
172 | 183 | | |
173 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
196 | 197 | | |
197 | 198 | | |
198 | 199 | | |
199 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
200 | 203 | | |
201 | 204 | | |
202 | 205 | | |
| |||
265 | 268 | | |
266 | 269 | | |
267 | 270 | | |
268 | | - | |
269 | | - | |
270 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
271 | 277 | | |
272 | 278 | | |
273 | 279 | | |
274 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
275 | 296 | | |
276 | 297 | | |
277 | 298 | | |
| |||
1017 | 1038 | | |
1018 | 1039 | | |
1019 | 1040 | | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
1020 | 1045 | | |
1021 | 1046 | | |
1022 | | - | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
1023 | 1051 | | |
1024 | 1052 | | |
1025 | 1053 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
213 | 214 | | |
214 | 215 | | |
215 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
216 | 223 | | |
217 | 224 | | |
218 | 225 | | |
219 | 226 | | |
220 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
221 | 236 | | |
222 | 237 | | |
223 | 238 | | |
| |||
0 commit comments