Commit 3c29af7
committed
feat(proto)!: allow non-UTF-8 header values and align validation with the server
The NATS Server relays the header block of HMSG messages verbatim,
without validating header names or values: values containing obs-text
(0x80-0xFF), invalid UTF-8 or nothing at all pass through untouched,
and nats.go is able to produce all of them. Watermelon instead decoded
values into a UTF-8 `ByteString`, failing the decode of messages other
clients handle fine, and the various validators enforced arbitrary
length caps and Unicode whitespace rules the server knows nothing
about.
Store `HeaderValue` as raw `Bytes`, following the design of the `http`
crate: `as_str` and the `str` conversion traits are replaced by a
fallible `to_str` plus `as_bytes`, and the decoder now accepts
non-UTF-8 and empty values, the latter previously panicking the
header line parser.
Validators now reject only what the wire cannot carry, dropping the
arbitrary length limits: subjects and queue groups travel inside
whitespace delimited control lines, so ` `, `\t`, `\r` and `\n`
remain rejected; header values only reject `\r` and `\n`; header
names additionally reject `:` and non-ASCII bytes, which Go's
`textproto.ReadMIMEHeader` errors on when nats.go parses received
headers.
JetStream publishes now validate user-supplied `Nats-*` header values
via the new `JetstreamError::HeaderValue` variant instead of trusting
them, and the decoder's maximum head length is raised to 128 KiB:
routed, leafnode and gateway connections may produce arg lines of up
to 64 KiB, well past the previous 16 KiB limit.1 parent 56c9ba9 commit 3c29af7
10 files changed
Lines changed: 348 additions & 183 deletions
File tree
- watermelon-proto/src
- headers
- proto
- decoder
- encoder
- watermelon/src/client/jetstream
- commands
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
25 | | - | |
26 | 24 | | |
27 | 25 | | |
28 | 26 | | |
| |||
170 | 168 | | |
171 | 169 | | |
172 | 170 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
| 171 | + | |
| 172 | + | |
178 | 173 | | |
179 | 174 | | |
180 | 175 | | |
| |||
183 | 178 | | |
184 | 179 | | |
185 | 180 | | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
195 | 193 | | |
196 | 194 | | |
197 | 195 | | |
| |||
200 | 198 | | |
201 | 199 | | |
202 | 200 | | |
| 201 | + | |
203 | 202 | | |
204 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
205 | 206 | | |
206 | 207 | | |
207 | 208 | | |
| |||
210 | 211 | | |
211 | 212 | | |
212 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
213 | 240 | | |
0 commit comments