Commit 6b2f24c
committed
fix(mcp): add SSRF protection to OAuth metadata discovery
The OAuth discovery flow in oauth-utils.ts and oauth-provider.ts
fetches URLs received directly from external MCP server responses
without any SSRF validation, unlike web-fetch.ts which already
uses isLoopbackHost() and resolveAndValidateDns() from utils/fetch.ts.
A malicious MCP server can return private/internal IPs in:
- WWW-Authenticate: Bearer resource_metadata="http://169.254.169.254/..."
- /.well-known/oauth-protected-resource: {authorization_servers: ["http://169.254.169.254"]}
- /.well-known/oauth-authorization-server: {registration_endpoint: "http://10.x.x.x/admin"}
This causes gemini-cli to make GET and POST requests to cloud IMDS
endpoints (AWS 169.254.169.254, GCP metadata.google.internal, Azure
169.254.169.254) or internal services on the developer's network.
Fix: apply the same isLoopbackHost() + resolveAndValidateDns() guards
already used in web-fetch.ts to:
- OAuthUtils.fetchProtectedResourceMetadata()
- OAuthUtils.fetchAuthorizationServerMetadata()
- MCPOAuthProvider.registerClient()1 parent 17a70c7 commit 6b2f24c
2 files changed
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
114 | 127 | | |
115 | 128 | | |
116 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
| |||
97 | 101 | | |
98 | 102 | | |
99 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
100 | 118 | | |
101 | 119 | | |
102 | 120 | | |
| |||
121 | 139 | | |
122 | 140 | | |
123 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
124 | 156 | | |
125 | 157 | | |
126 | 158 | | |
| |||
0 commit comments