Commit 4c52ca5
authored
fmt: fix ANSI escape sequence injection vulnerability (#3368)
Fixes a security vulnerability where ANSI escape sequences in user input could be injected into terminal output, potentially allowing attackers to manipulate terminal behavior through log messages and error displays. The vulnerability occurred when user-controlled content was formatted using Display (`{}`) instead of Debug (`{:?}`) formatting, allowing raw ANSI sequences to pass through unescaped. Changes: - Add streaming ANSI escape wrapper to avoid string allocations - Escape message content in default and pretty formatters - Escape error Display content in all error formatting paths - Add comprehensive integration tests for all formatter types The fix specifically targets untrusted user input while preserving the ability for applications to deliberately include formatting in trusted contexts like thread names. Security impact: Prevents terminal injection attacks such as title bar manipulation, screen clearing, and other malicious terminal control sequences that could be injected through log messages.1 parent f71cebe commit 4c52ca5
File tree
6 files changed
+358
-8
lines changed- tracing-subscriber
- src/fmt/format
- tests
6 files changed
+358
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
1 | 9 | | |
2 | 10 | | |
3 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
| |||
1257 | 1261 | | |
1258 | 1262 | | |
1259 | 1263 | | |
1260 | | - | |
| 1264 | + | |
1261 | 1265 | | |
1262 | 1266 | | |
1263 | 1267 | | |
1264 | 1268 | | |
1265 | 1269 | | |
1266 | 1270 | | |
1267 | 1271 | | |
1268 | | - | |
| 1272 | + | |
1269 | 1273 | | |
1270 | 1274 | | |
1271 | 1275 | | |
| |||
1287 | 1291 | | |
1288 | 1292 | | |
1289 | 1293 | | |
1290 | | - | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
1291 | 1298 | | |
1292 | 1299 | | |
1293 | 1300 | | |
| |||
1326 | 1333 | | |
1327 | 1334 | | |
1328 | 1335 | | |
1329 | | - | |
| 1336 | + | |
1330 | 1337 | | |
1331 | 1338 | | |
1332 | 1339 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
457 | 457 | | |
458 | 458 | | |
459 | 459 | | |
460 | | - | |
| 460 | + | |
461 | 461 | | |
462 | 462 | | |
463 | 463 | | |
464 | 464 | | |
465 | 465 | | |
466 | 466 | | |
467 | 467 | | |
468 | | - | |
| 468 | + | |
469 | 469 | | |
470 | 470 | | |
471 | 471 | | |
| |||
475 | 475 | | |
476 | 476 | | |
477 | 477 | | |
478 | | - | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
479 | 482 | | |
480 | 483 | | |
481 | 484 | | |
| |||
0 commit comments