im
Clone
https://git.tahinli.com/Tahinli/im.git
0 watching0 forksRustAGPL-3.0542.8 KiBb9f0726Tahinli27 days ago34 commits
| 1 | //! The client address of a request, for throttling and for the audit log. |
| 2 | //! |
| 3 | //! The TCP peer is the client, unless the peer is in `trusted_proxies`. Only then is |
| 4 | //! `X-Forwarded-For` read: from the right, skipping trusted hops, the first untrusted address is the |
| 5 | //! client. Any unusable header falls back to the peer, so a spoofed header from an untrusted peer is |
| 6 | //! never believed. IPv6 is bucketed by /64 for throttling, so one client holding a /64 cannot |
| 7 | //! multiply its attempt budget. |
| 8 | |
| 9 | use ; |
| 10 | |
| 11 | use ; |
| 12 | use IpNet; |
| 13 | use ; |
| 14 | |
| 15 | use crateAppState; |
| 16 | |
| 17 | /// The header a trusted proxy appends the client address to. |
| 18 | const FORWARDED_FOR: &str = "x-forwarded-for"; |
| 19 | |
| 20 | /// The client address for throttling: the exact address, with IPv6 bucketed by /64. |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | /// The exact client address of this request, normalised but not bucketed. Used for the audit log |
| 26 | /// and the session list. A request without a peer address (not possible over TCP) maps to the |
| 27 | /// unspecified address. |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | /// Pure form of [`client_addr`]. `forwarded` is the combined `X-Forwarded-For` value, or empty. |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | /// IPv4-mapped IPv6 addresses are reported as the IPv4 address they carry. |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | /// Clears the host half of an IPv6 address, so every address of a /64 shares one bucket. |
| 73 | |
| 74 | |
| 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 |