1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! Front-end DoS limits.
//!
//! These limits are uniformly applied at parser entry points so a
//! malicious query string can't exhaust recursion stack, RAM, or
//! identifier bookkeeping. Limit values are documented in
//! `docs/security/parser-limits.md` (issue #87).
//!
//! # Defaults
//!
//! | Limit | Default | Rationale |
//! |-----------------------|---------|-------------------------------------------------|
//! | `max_depth` | 32 | Recursive descent + Pratt; above typical |
//! | | | hand-written queries (≤ 12). |
//! | `max_input_bytes` | 1 MiB | Hard cap on the token stream input. |
//! | `max_identifier_chars`| 256 | Long enough for legitimate UUID-tagged names, |
//! | | | short enough to bound HashMap pressure. |
//! | `max_tokens` | 8192 | Bounds token-driven parser work even when input |
//! | | | bytes and recursion depth stay below their caps. |
//!
//! `ParserLimits` is consumed both by the [`crate::lexer`] (identifier and
//! input-byte caps, checked during tokenization) and by the parser proper
//! (recursion-depth cap), which still lives in `reddb-server` and reaches
//! this type through its re-export shim.
/// Hard limits enforced by the front-end.
///
/// The fields are public so the harness module (used by tests in
/// `tests/support/parser_hardening`) can mutate them inline. Default
/// values match production defaults.
/// Maximum nesting depth for JSON object literals, validated after
/// parsing by [`crate::parser::dml::json_literal_depth_check`] using
/// an iterative stack walk.
///
/// Defined here — alongside [`ParserLimits`] and [`DepthCounter`] —
/// so every depth-cap constant is co-located in one module. Expression
/// and subquery nesting are guarded inline by
/// [`crate::parser::Parser::enter_depth`] /
/// [`crate::parser::Parser::exit_depth`] against
/// [`ParserLimits::max_depth`].
pub const JSON_LITERAL_MAX_DEPTH: u32 = 128;