Commit 5080546
feat: Add nested comprehension depth limits (fixes #35)
Implements protection against resource exhaustion from deeply nested
CEL comprehensions by enforcing a maximum nesting depth of 3 levels.
**Changes:**
- Added maxComprehensionDepth constant (value: 3)
- Added comprehensionDepth field to converter struct to track nesting
- Implemented depth checking in visitComprehension() with automatic
increment/decrement using defer
- Modified wrapConversionError() to preserve specific error messages
through the wrapping chain
- Added comprehensive test suite with 6 test functions covering all
boundary conditions and edge cases
**Security Impact:**
- Prevents DoS attacks through expensive nested UNNEST/subquery operations
- Addresses CWE-400: Uncontrolled Resource Consumption
- Users attempting to exceed depth limit receive clear error messages
**Examples:**
- Depth 1-3: ✓ Allowed (e.g., list1.map(x, list2.filter(y, list3.exists(z, z > y))))
- Depth 4+: ✗ Rejected with error "comprehension nesting depth N exceeds maximum of 3"
All existing tests continue to pass. Backward compatible for expressions
within the depth limit.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 3b23305 commit 5080546
File tree
4 files changed
+412
-28
lines changed4 files changed
+412
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
3 | 12 | | |
4 | 13 | | |
5 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
| |||
267 | 271 | | |
268 | 272 | | |
269 | 273 | | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
280 | 285 | | |
281 | 286 | | |
282 | 287 | | |
| |||
1016 | 1021 | | |
1017 | 1022 | | |
1018 | 1023 | | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
1019 | 1034 | | |
1020 | 1035 | | |
1021 | 1036 | | |
| |||
0 commit comments