Commit d39a98c
observatory
x509util: fix SSRF hostname bypass in rejectPrivateHost()
PR google#1761 introduced rejectPrivateHost() to block SSRF via
private IP addresses, but only checked net.ParseIP() which
returns nil for hostnames. DNS hostnames resolving to private
or loopback addresses bypassed the fix entirely.
This change resolves hostnames via net.LookupHost() before
IP validation, blocking bypasses such as:
- localhost → 127.0.0.1 (loopback)
- metadata.google.internal → 169.254.169.254 (GCP)
- kubernetes.default.svc → 10.x.x.x (k8s)
Also adds:
- rejectPrivateHost() to ReadFileOrURL() and GetIssuer()
- defer rsp.Body.Close() to prevent resource leaks
- Tests for hostname bypass and SSRF protection
Fixes incomplete fix in PR google#1761 (Issue google#1759)1 parent dc95553 commit d39a98c
2 files changed
Lines changed: 113 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
29 | 62 | | |
30 | 63 | | |
31 | 64 | | |
| |||
45 | 78 | | |
46 | 79 | | |
47 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
48 | 88 | | |
49 | 89 | | |
50 | 90 | | |
51 | 91 | | |
| 92 | + | |
52 | 93 | | |
53 | 94 | | |
54 | 95 | | |
| |||
84 | 125 | | |
85 | 126 | | |
86 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
87 | 131 | | |
88 | 132 | | |
89 | 133 | | |
90 | 134 | | |
| 135 | + | |
91 | 136 | | |
92 | 137 | | |
93 | 138 | | |
| |||
99 | 144 | | |
100 | 145 | | |
101 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
102 | 157 | | |
103 | 158 | | |
104 | 159 | | |
| |||
| 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 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
0 commit comments