Commit 4625b15
Sanitize server-supplied strings at decoder boundary
FailureResponse.message, LeaderResponse.address, and
ServersResponse.nodes[*].address are decoded from server-supplied
bytes and flow directly into exception messages and log records. A
malicious or compromised peer could embed ANSI escape sequences to
corrupt operator terminals, CR/LF to forge log entries, or NUL bytes
that upset some log backends.
Replace C0 control characters (except tab 0x09 and LF 0x0A) and DEL
(0x7F) with the literal '?' in these three fields. CR is dropped
because it is the log-injection vector alongside LF, and LF alone is
enough to render legitimate multi-line server diagnostics. The
sanitization lives in a small _sanitize_server_text helper and is
called only from the three decode_body sites — SQL text, column
names, and other application strings are intentionally untouched.
Tests cover ANSI clear-screen, CR forging, raw NUL (hand-built body
to bypass encode_text's strict encoding), tab/LF preservation, and
all three message types.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 2f34907 commit 4625b15
2 files changed
Lines changed: 103 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
39 | 40 | | |
40 | 41 | | |
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 | + | |
42 | 66 | | |
43 | 67 | | |
44 | 68 | | |
| |||
66 | 90 | | |
67 | 91 | | |
68 | 92 | | |
69 | | - | |
| 93 | + | |
70 | 94 | | |
71 | 95 | | |
72 | 96 | | |
| |||
94 | 118 | | |
95 | 119 | | |
96 | 120 | | |
97 | | - | |
| 121 | + | |
98 | 122 | | |
99 | 123 | | |
100 | 124 | | |
| |||
104 | 128 | | |
105 | 129 | | |
106 | 130 | | |
107 | | - | |
| 131 | + | |
108 | 132 | | |
109 | 133 | | |
110 | 134 | | |
| |||
613 | 637 | | |
614 | 638 | | |
615 | 639 | | |
| 640 | + | |
616 | 641 | | |
617 | 642 | | |
618 | 643 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1311 | 1311 | | |
1312 | 1312 | | |
1313 | 1313 | | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
1314 | 1389 | | |
1315 | 1390 | | |
1316 | 1391 | | |
| |||
0 commit comments