Claude MCP skill SSRF via URL redirect in OAuth authorization code flow — SA-SKL-SSRF14
OAuth authorization code flows introduce multiple points where server-side HTTP requests are made to URLs derived from user-controlled or provider-supplied data: the redirect URI, the token endpoint, the userinfo endpoint, and any profile data URLs returned by the provider. Each of these is an SSRF injection point if the URL is not validated against a strict allowlist or the resolved IP is not checked before the request is dispatched. Four SA-SKL-SSRF14 patterns cover the most common SSRF injection paths that appear in Claude MCP skill OAuth integrations.
redirect_uri from the state JWT and follows it after the code exchange; no allowlist check; attacker crafts state with redirect_uri=http://169.254.169.254/latest/meta-data/iam/security-credentials/prod-role; server fetches cloud instance metadata and returns it in the redirect responserepos_url from the GitHub user object in the API response without validating the host is api.github.com; attacker registers a GitHub org whose repos_url field is set to an internal Elasticsearch endpointavatar_url from the provider userinfo response without resolving the DNS name and checking the resulting IP; avatar_url pointing to http://10.0.0.1:9200/_cat/indices is fetched server-side and the response body is returned to the clientdiscovery_url query parameter in the authorization request; the discovery document is fetched from the attacker-supplied URL; token_endpoint in the response is extracted and used for the code exchange without host pinningSSRF14-001 — OAuth state redirect_uri to cloud IMDS
The OAuth state parameter is intended to carry client-side state across the redirect — typically a random nonce to prevent CSRF. Some implementations also encode the post-auth redirect destination in the state. When the OAuth callback handler decodes this state and follows the embedded redirect URI by making a server-side fetch (to validate it, to pass tokens, or to proxy the final redirect), and that URI is not validated against a pre-registered allowlist, an attacker who controls the state can point the redirect URI at any internal URL reachable by the server. Cloud provider instance metadata services at 169.254.169.254 are the classic target: they return IAM credentials and service configuration without authentication.
// VULNERABLE — SSRF14-001 (CRITICAL)
// state parameter decoded and redirect_uri followed server-side without host check.
// Attacker encodes: {"redirect_uri": "http://169.254.169.254/latest/meta-data/..."}
router.get('/auth/callback', async (req, res) => {
const { code, state } = req.query;
// Decode state to get the original redirect destination
const { redirect_uri, nonce } = JSON.parse(
Buffer.from(state as string, 'base64').toString()
);
// Exchange code for tokens
const tokens = await exchangeCode(code as string);
const user = await fetchUserInfo(tokens.access_token);
await setSession(req, user);
// VULNERABLE: follows redirect_uri from attacker-controlled state parameter
// server-side fetch goes to 169.254.169.254 and returns IAM credentials
const response = await fetch(redirect_uri); // SSRF
res.redirect(redirect_uri);
});
// FIXED — SSRF14-001
// Validate redirect_uri against an allowlist of pre-registered URLs before following.
// Never make a server-side fetch to redirect_uri — just redirect the client.
const ALLOWED_REDIRECT_URIS = new Set([
'https://skillaudit.dev/dashboard',
'https://skillaudit.dev/settings/integrations',
]);
router.get('/auth/callback', async (req, res) => {
const { code, state } = req.query;
const { redirect_uri, nonce } = JSON.parse(
Buffer.from(state as string, 'base64').toString()
);
// FIX: validate against allowlist before ANY use of redirect_uri
if (!ALLOWED_REDIRECT_URIS.has(redirect_uri)) {
return res.status(400).json({ error: 'Invalid redirect_uri' });
}
const tokens = await exchangeCode(code as string);
const user = await fetchUserInfo(tokens.access_token);
await setSession(req, user);
// FIX: client-side redirect only — no server-side fetch of redirect_uri
res.redirect(redirect_uri);
});
SSRF14-002 — GitHub API repos_url from response body used without host check
When a user authenticates via GitHub OAuth, the typical next step is to fetch the user's profile from the GitHub API to get their username, email, and organization memberships. The GitHub user object contains several URL fields — repos_url, organizations_url, subscriptions_url — that are normally api.github.com URLs. If the OAuth callback directly uses these URL fields to make follow-up API calls without validating the host, an attacker who can influence the user object (e.g. by pre-configuring their GitHub profile or by being an org admin) can point one of these fields at an internal service. GitHub does not expose these fields as user-editable, but the application should not trust external API responses to only contain safe URLs.
// VULNERABLE — SSRF14-002 (HIGH)
// repos_url taken from GitHub API response and fetched without host check.
// Attacker crafts an API response (e.g. via a MitM or cached fixture) where
// repos_url = http://elasticsearch.internal:9200/_cat/indices
async function fetchGitHubUserData(accessToken: string) {
const userRes = await fetch('https://api.github.com/user', {
headers: { Authorization: `Bearer ${accessToken}` },
});
const user = await userRes.json();
// VULNERABLE: repos_url from external API response, no host check
const reposRes = await fetch(user.repos_url); // SSRF if repos_url is poisoned
const repos = await reposRes.json();
return { user, repos };
}
// FIXED — SSRF14-002
// Construct the repos URL from the username returned by the API.
// Never use URL fields from external API responses for server-side fetches.
async function fetchGitHubUserData(accessToken: string) {
const userRes = await fetch('https://api.github.com/user', {
headers: { Authorization: `Bearer ${accessToken}` },
});
const user = await userRes.json();
// FIX: construct URL from username, do not use repos_url from response
if (typeof user.login !== 'string' || !/^[\w-]+$/.test(user.login)) {
throw new Error('Invalid GitHub username in API response');
}
const safeReposUrl = `https://api.github.com/users/${user.login}/repos`;
const reposRes = await fetch(safeReposUrl);
const repos = await reposRes.json();
return { user, repos };
}
SSRF14-003 — Provider avatar_url fetched without DNS IP check
Many OAuth providers return an avatar_url in the userinfo response. If the application proxies avatar images through the backend (to avoid mixed-content warnings or to cache them), it must resolve the DNS name in the URL and verify that the resulting IP is not in a private or link-local range before making the request. Without this check, an attacker who can supply a custom OAuth provider (e.g. in an enterprise SSO integration) or who registers with a provider that allows custom avatar URLs can set their avatar to an internal address. The fix is to resolve DNS before fetching and block requests to RFC 1918 and link-local addresses.
// VULNERABLE — SSRF14-003 (HIGH)
// avatar_url from OAuth provider userinfo response fetched server-side.
// No DNS resolution or IP check. URL could point to 10.x.x.x or 169.254.x.x.
router.get('/api/avatar/:userId', authenticate, async (req, res) => {
const user = await db.get('SELECT avatar_url FROM users WHERE id = ?', req.params.userId);
// VULNERABLE: proxies any URL stored in avatar_url, including internal addresses
const avatarRes = await fetch(user.avatar_url);
res.set('Content-Type', avatarRes.headers.get('Content-Type') || 'image/png');
avatarRes.body?.pipe(res);
});
// FIXED — SSRF14-003
// Resolve DNS and check the IP against private/link-local ranges before fetching.
import dns from 'dns/promises';
import ipaddr from 'ipaddr.js';
const BLOCKED_RANGES = ['private', 'linkLocal', 'loopback', 'uniqueLocal', 'ipv4Mapped'];
async function isSafeUrl(urlStr: string): Promise<boolean> {
try {
const url = new URL(urlStr);
if (!['http:', 'https:'].includes(url.protocol)) return false;
const addrs = await dns.lookup(url.hostname, { all: true });
for (const { address } of addrs) {
const parsed = ipaddr.parse(address);
const range = parsed.range();
if (BLOCKED_RANGES.includes(range)) return false;
}
return true;
} catch {
return false;
}
}
router.get('/api/avatar/:userId', authenticate, async (req, res) => {
const user = await db.get('SELECT avatar_url FROM users WHERE id = ?', req.params.userId);
// FIX: DNS-check the URL before fetching
if (!await isSafeUrl(user.avatar_url)) {
return res.status(400).json({ error: 'Invalid avatar URL' });
}
const avatarRes = await fetch(user.avatar_url);
res.set('Content-Type', avatarRes.headers.get('Content-Type') || 'image/png');
avatarRes.body?.pipe(res);
});
SSRF14-004 — OAuth discovery document URL taken from request parameter
OIDC-compliant OAuth providers publish a discovery document at a well-known URL (e.g. https://accounts.google.com/.well-known/openid-configuration) that lists the authorization endpoint, token endpoint, and JWKS URI. When an MCP skill supports multiple OAuth providers dynamically and accepts the discovery document URL from the incoming authorization request, an attacker can supply a URL pointing to their own server. Their discovery document will list a token_endpoint under their control — the backend then sends the authorization code and client secret to the attacker's token endpoint, completing a credential steal.
// VULNERABLE — SSRF14-004 (HIGH)
// discovery_url from request query parameter. Attacker supplies their own server.
// token_endpoint from attacker's discovery doc receives the auth code + client_secret.
router.get('/auth/start', (req, res) => {
const { discovery_url, provider } = req.query;
// VULNERABLE: discovery_url comes from the request, not from env config
req.session.pendingDiscoveryUrl = discovery_url;
// ... build auth URL using endpoints from discovery doc
res.redirect(buildAuthUrl(discovery_url as string));
});
router.get('/auth/callback', async (req, res) => {
const { code } = req.query;
const discoveryUrl = req.session.pendingDiscoveryUrl;
// VULNERABLE: fetches attacker-controlled discovery document
const discoveryDoc = await fetch(discoveryUrl).then(r => r.json());
// token_endpoint is now the attacker's server
const tokens = await fetch(discoveryDoc.token_endpoint, {
method: 'POST',
body: new URLSearchParams({ code, client_secret: process.env.OAUTH_SECRET }),
});
});
// FIXED — SSRF14-004
// Pin discovery document URLs in environment configuration.
// Never accept the discovery URL from a request parameter.
const PROVIDER_DISCOVERY_URLS: Record<string, string> = {
github: 'https://token.actions.githubusercontent.com/.well-known/openid-configuration',
google: 'https://accounts.google.com/.well-known/openid-configuration',
okta: process.env.OKTA_DISCOVERY_URL!, // set at deploy time, not from request
};
router.get('/auth/start', (req, res) => {
const provider = req.query.provider as string;
// FIX: look up discovery URL from env config — never from request
const discoveryUrl = PROVIDER_DISCOVERY_URLS[provider];
if (!discoveryUrl) return res.status(400).json({ error: 'Unknown provider' });
req.session.pendingProvider = provider;
res.redirect(buildAuthUrl(discoveryUrl));
});
router.get('/auth/callback', async (req, res) => {
const provider = req.session.pendingProvider;
const discoveryUrl = PROVIDER_DISCOVERY_URLS[provider]; // safe: from config
const discoveryDoc = await fetch(discoveryUrl).then(r => r.json());
// token_endpoint is now always the legitimate provider's endpoint
const tokens = await exchangeCode(discoveryDoc.token_endpoint, req.query.code);
});
SkillAudit detection: SA-SKL-SSRF14 flags OAuth callback handlers that decode and follow redirect_uri from state parameters without an allowlist, follow-up fetch calls using URL fields from OAuth provider API responses (e.g. repos_url, avatar_url, organizations_url) without host validation, server-side image proxy routes that do not resolve DNS and check for private IP ranges, and OAuth flows that read discovery document URLs from request parameters rather than environment configuration. Run a free audit at skillaudit.dev.
| Pattern | CVSS | Impact | Fix |
|---|---|---|---|
| SSRF14-001 state redirect_uri | 9.8 Critical | Cloud IMDS credential theft; internal service access | Validate redirect_uri against pre-registered allowlist; no server-side fetch |
| SSRF14-002 repos_url from API body | 8.6 High | Internal service request via poisoned GitHub API field | Construct URL from username; never use URL fields from external API responses |
| SSRF14-003 avatar_url no DNS check | 8.1 High | Server-side request to internal IP via provider-supplied URL | DNS-resolve before fetch; block RFC 1918 and link-local addresses |
| SSRF14-004 discovery URL from request | 8.1 High | Client secret and auth code sent to attacker token endpoint | Pin discovery URLs in environment config; never accept from request |