Commit 84de0a8
Bound multipart text/plain field materialization in Jersey AppSec (#11944)
Bound multipart text/plain field materialization in Jersey AppSec
Jersey 2/3 AppSec instrumentation read text/plain multipart field
values via the unbounded getValue() and accumulated an unlimited
number of distinct field names, allowing a crafted multipart request
to exhaust heap/CPU before WAF limits apply. Reuse the existing
byte-capped MultipartContentDecoder and the configured file-content
limits (MAX_CONTENT_BYTES, MAX_FILES_TO_INSPECT) to bound both the
size of each field value and the number of distinct field names
collected.
fix: bound multipart body map by total value count and avoid unguarded getName()
- Cap now bounds total accumulated values in the body map, not just distinct
field names, closing a bypass where repeating a field name skipped the limit.
- Derive the body map key from FormDataContentDisposition.getName() (a safe
field accessor) instead of FormDataBodyPart.getName(), which re-parses the
disposition header and can throw on malformed input.
Addresses Codex review findings 1 and 3 on PR #11944.
fix: default multipart content decoding to UTF-8 instead of platform charset
Charset.defaultCharset() depends on the JVM/platform locale and can differ
from the UTF-8 default Jersey's own getValue() used, corrupting text
captured by AppSec on JVMs whose platform charset isn't UTF-8.
Addresses Codex review finding 2 on PR #11944.
Revert "fix: default multipart content decoding to UTF-8 instead of platform charset"
This reverts commit e25666a.
fix: scope UTF-8 default charset to Jersey, revert change to shared MultipartContentDecoder
MultipartContentDecoder is shared by Tomcat, Netty, Vert.x, RESTEasy and
commons-fileupload. Its Charset.defaultCharset() fallback was a deliberate,
reviewed decision (Manuel, PR #11198) - changing it in e25666a silently
altered production behavior for all those integrations, not just Jersey.
Revert the shared decoder change and instead default to UTF-8 only in
Jersey's MultiPartHelper, matching Jersey's own getValue() default, by
appending charset=UTF-8 to the contentType before calling the shared decoder.
fix: limit UTF-8 charset default to the body-map text-field path
readContent() served both the bodyMap (text field) and filesContent
call sites, so the Jersey-local UTF-8 default leaked into file
content too. Split it into readContent() (UTF-8 default, text
fields) and readFileContent() (unmodified content type, parity with
MultipartContentDecoder's fallback used by file content in every
other multipart helper).
Merge branch 'master' into APMSP-3237
Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>1 parent 6821684 commit 84de0a8
4 files changed
Lines changed: 358 additions & 34 deletions
File tree
- dd-java-agent/instrumentation/jersey/jersey-appsec
- jersey-appsec-2.0/src
- main/java/datadog/trace/instrumentation/jersey2
- test/groovy
- jersey-appsec-3.0/src
- main/java/datadog/trace/instrumentation/jersey3
- test/groovy
Lines changed: 40 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | 31 | | |
37 | 32 | | |
38 | 33 | | |
| |||
41 | 36 | | |
42 | 37 | | |
43 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
44 | 49 | | |
45 | 50 | | |
46 | 51 | | |
| |||
49 | 54 | | |
50 | 55 | | |
51 | 56 | | |
52 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
53 | 65 | | |
| 66 | + | |
54 | 67 | | |
55 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
56 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
57 | 84 | | |
58 | 85 | | |
59 | 86 | | |
60 | 87 | | |
61 | 88 | | |
62 | | - | |
63 | | - | |
64 | 89 | | |
65 | 90 | | |
66 | 91 | | |
67 | 92 | | |
68 | 93 | | |
69 | 94 | | |
70 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
71 | 103 | | |
72 | 104 | | |
73 | 105 | | |
| |||
Lines changed: 139 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | | - | |
22 | | - | |
23 | | - | |
| 23 | + | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
| 61 | + | |
59 | 62 | | |
60 | 63 | | |
61 | | - | |
62 | | - | |
63 | | - | |
| 64 | + | |
| 65 | + | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
| |||
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
74 | 204 | | |
75 | 205 | | |
76 | 206 | | |
| |||
96 | 226 | | |
97 | 227 | | |
98 | 228 | | |
99 | | - | |
| 229 | + | |
100 | 230 | | |
101 | 231 | | |
102 | 232 | | |
| |||
107 | 237 | | |
108 | 238 | | |
109 | 239 | | |
| 240 | + | |
110 | 241 | | |
111 | 242 | | |
112 | | - | |
113 | | - | |
| 243 | + | |
114 | 244 | | |
115 | 245 | | |
116 | 246 | | |
| |||
Lines changed: 40 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | 31 | | |
37 | 32 | | |
38 | 33 | | |
| |||
41 | 36 | | |
42 | 37 | | |
43 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
44 | 49 | | |
45 | 50 | | |
46 | 51 | | |
| |||
49 | 54 | | |
50 | 55 | | |
51 | 56 | | |
52 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
53 | 65 | | |
| 66 | + | |
54 | 67 | | |
55 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
56 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
57 | 84 | | |
58 | 85 | | |
59 | 86 | | |
60 | 87 | | |
61 | 88 | | |
62 | | - | |
63 | | - | |
64 | 89 | | |
65 | 90 | | |
66 | 91 | | |
67 | 92 | | |
68 | 93 | | |
69 | 94 | | |
70 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
71 | 103 | | |
72 | 104 | | |
73 | 105 | | |
| |||
0 commit comments