Commit e47a8b3
compiler: validate $ref URLs to prevent SSRF in fetchFile
fetchFile() previously called http.Get() with any URL derived from a
$ref value in a user-supplied OpenAPI spec, with no validation of the
scheme or destination host. This allowed an attacker to craft a spec
that caused gnostic to make HTTP requests to internal network addresses,
cloud instance metadata endpoints (e.g. 169.254.169.254), or arbitrary
non-HTTP schemes.
Add validateFetchURL() which enforces:
- Scheme allowlist: only "http" and "https" are permitted.
- Private/reserved IP blocklist: requests to RFC 1918 addresses,
loopback (127.0.0.0/8), link-local (169.254.0.0/16 including cloud
IMDS), RFC 6598 shared space, and IPv6 equivalents are rejected.
fetchFile() now returns an error before issuing the HTTP request if the
URL fails either check.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 289d7b4 commit e47a8b3
1 file changed
Lines changed: 56 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 | | |
| |||
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
148 | 201 | | |
149 | 202 | | |
150 | 203 | | |
| |||
160 | 213 | | |
161 | 214 | | |
162 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
163 | 219 | | |
164 | 220 | | |
165 | 221 | | |
| |||
0 commit comments