Commit 23b7e0f
committed
feat(auth): implement inbound access control and non-loopback bind validation guard
This change introduces local inbound authentication and security gating to protect proxy interfaces from unauthorized usage and resource exhaustion (quota theft) when exposed on local networks or the public internet.
1. Secure Configuration Defaults & Redaction (src/config.rs):
- Changed the default `listen_host` from `0.0.0.0` to `127.0.0.1` (loopback only) to ensure secure-by-default behavior upon initial deployment.
- Changed the default `block_stun` value to `true` to block WebRTC IP address discovery probes.
- Implemented a custom `std::fmt::Debug` implementation for the `Config` struct that automatically hides the `inbound_password` field with `"[REDACTED]"`.
- Exposed `Config::validate` as a public method so that UI saving operations can inspect config safety before serialization.
2. Non-Loopback Bind Validation Guard (src/config.rs):
- Extended `Config::validate` to inspect the listen address.
- If the address binds to any non-loopback interface (such as wildcards `0.0.0.0` and `::`, or external LAN/WAN interfaces) and `inbound_username` or `inbound_password` is empty, validation is rejected with a descriptive security error warning of quota theft and unauthorized usage risks.
3. SOCKS5 Inbound Authentication (src/proxy_server.rs):
- In SOCKS5 client negotiation, if inbound credentials are set, the proxy advertises Username/Password authentication (Method 0x02). If the client does not support it, it rejects the handshake with 0xFF.
- Implemented RFC 1929 authentication subnegotiation: parses sub-protocol version 1, reads the length-prefixed username and password, performs validation, and returns status 0x00 on success or 0x01 on failure (terminating the connection).
- If no inbound credentials are set, it defaults to the standard no-authentication (0x00) method.
4. HTTP Inbound Proxy Authentication (src/proxy_server.rs):
- In HTTP/HTTPS client handling, if inbound credentials are set, the proxy inspects the `Proxy-Authorization` header (checked case-insensitively).
- Parses the authentication token in `Basic <Base64>` format, decodes it using the STANDARD base64 engine, and verifies the credentials.
- If credentials are missing or incorrect, it returns a local `407 Proxy Authentication Required` status with `Proxy-Authenticate: Basic realm="mhrv-rs"` and terminates the socket connection.
5. UI Access Controls & Badge System (src/bin/ui.rs):
- Added an Obsidian-themed UI panel for "Inbound Access Control" containing username/password input fields, visibility toggles, and a secure random credentials generator.
- Rendered dynamic security status badges based on the bind configuration: a green "Local Only" badge when bound to loopback interfaces, and an orange/yellow "LAN Exposed" warning badge with security warning copy when bound to non-loopback interfaces.
- Plumbed `Config::validate` into UI save routines to present configuration safety warnings to the user via toast notifications.
Verification:
- Added `test_non_loopback_bind_requires_credentials` in `src/config.rs` to verify validation of local loopback hosts (IPv4, IPv6, bracketed IPv6) and wildcards.
- Added `test_handle_http_client_auth` in `src/proxy_server.rs` to verify local 407 response behavior and successful credentials passage.
- Added `test_handle_socks5_client_auth` in `src/proxy_server.rs` to verify SOCKS5 RFC 1929 method negotiation, subnegotiation failure, and subnegotiation success.
- Verified that all unit and integration tests compile and run green.1 parent bdbc4c0 commit 23b7e0f
3 files changed
Lines changed: 543 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
324 | 327 | | |
325 | 328 | | |
326 | 329 | | |
| |||
426 | 429 | | |
427 | 430 | | |
428 | 431 | | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
429 | 435 | | |
430 | 436 | | |
431 | 437 | | |
| |||
468 | 474 | | |
469 | 475 | | |
470 | 476 | | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
471 | 480 | | |
472 | 481 | | |
473 | 482 | | |
| |||
658 | 667 | | |
659 | 668 | | |
660 | 669 | | |
661 | | - | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
662 | 675 | | |
663 | 676 | | |
664 | 677 | | |
| |||
749 | 762 | | |
750 | 763 | | |
751 | 764 | | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
752 | 769 | | |
753 | 770 | | |
754 | 771 | | |
| |||
763 | 780 | | |
764 | 781 | | |
765 | 782 | | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
766 | 787 | | |
767 | 788 | | |
768 | 789 | | |
| |||
824 | 845 | | |
825 | 846 | | |
826 | 847 | | |
| 848 | + | |
| 849 | + | |
827 | 850 | | |
828 | 851 | | |
829 | 852 | | |
| |||
1226 | 1249 | | |
1227 | 1250 | | |
1228 | 1251 | | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 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 | + | |
1229 | 1388 | | |
1230 | 1389 | | |
1231 | 1390 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
88 | 92 | | |
89 | 93 | | |
90 | 94 | | |
| |||
405 | 409 | | |
406 | 410 | | |
407 | 411 | | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
408 | 461 | | |
409 | 462 | | |
410 | 463 | | |
| |||
511 | 564 | | |
512 | 565 | | |
513 | 566 | | |
514 | | - | |
| 567 | + | |
515 | 568 | | |
516 | 569 | | |
517 | 570 | | |
| |||
543 | 596 | | |
544 | 597 | | |
545 | 598 | | |
546 | | - | |
| 599 | + | |
547 | 600 | | |
548 | 601 | | |
549 | 602 | | |
| |||
564 | 617 | | |
565 | 618 | | |
566 | 619 | | |
567 | | - | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
568 | 638 | | |
569 | 639 | | |
570 | 640 | | |
| |||
801 | 871 | | |
802 | 872 | | |
803 | 873 | | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
804 | 919 | | |
805 | 920 | | |
806 | 921 | | |
| |||
0 commit comments