Commit cfb6d81
This commit addresses issue #33 by implementing SQL output length limits
to prevent Denial of Service attacks through resource exhaustion.
## Changes
### Core Implementation (cel2sql.go)
- Added `defaultMaxSQLOutputLength = 50000` constant
- Added `maxOutputLen` field to `convertOptions` and `converter` structs
- Created `WithMaxOutputLength()` functional option for custom limits
- Implemented output length check in `visit()` method
- Both `Convert()` and `ConvertParameterized()` now respect the limit
### Tests (output_length_test.go)
- Comprehensive test coverage for all scenarios:
- Default and custom output length limits
- Combination with other options (context, schemas, logger, maxDepth)
- Error message validation
- Counter reset between calls
- Large arrays, string concatenations, comprehensions
- Parameterized query support
### Documentation
- Updated CLAUDE.md with new "Resource Exhaustion Protection" section
- Updated README.md security features to include SQL output length limits
- Added examples for using `WithMaxOutputLength()`
## Security Impact
- Prevents DoS attacks via extremely large SQL output
- Addresses CWE-400 (Uncontrolled Resource Consumption)
- Default limit: 50,000 characters (configurable)
- Works seamlessly with existing security features
## Testing
- All tests pass (make test)
- Code passes linting (make lint)
- Coverage maintained at 90%+
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 40f34b0 commit cfb6d81
4 files changed
+668
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
389 | 433 | | |
390 | 434 | | |
391 | 435 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
57 | 62 | | |
58 | 63 | | |
59 | 64 | | |
| |||
137 | 142 | | |
138 | 143 | | |
139 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
140 | 165 | | |
141 | 166 | | |
142 | 167 | | |
| |||
158 | 183 | | |
159 | 184 | | |
160 | 185 | | |
161 | | - | |
162 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
163 | 189 | | |
164 | 190 | | |
165 | 191 | | |
| |||
174 | 200 | | |
175 | 201 | | |
176 | 202 | | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
182 | 209 | | |
183 | 210 | | |
184 | 211 | | |
| |||
225 | 252 | | |
226 | 253 | | |
227 | 254 | | |
228 | | - | |
229 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
230 | 258 | | |
231 | 259 | | |
232 | 260 | | |
| |||
241 | 269 | | |
242 | 270 | | |
243 | 271 | | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
250 | 279 | | |
251 | 280 | | |
252 | 281 | | |
| |||
278 | 307 | | |
279 | 308 | | |
280 | 309 | | |
| 310 | + | |
281 | 311 | | |
282 | 312 | | |
283 | 313 | | |
| |||
313 | 343 | | |
314 | 344 | | |
315 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
316 | 351 | | |
317 | 352 | | |
318 | 353 | | |
| |||
0 commit comments