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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//! OAuth / OIDC misconfiguration probe.
//!
//! Detects common misconfigurations in OAuth 2.0 and OpenID Connect deployments:
//!
//! - **Open redirect in `redirect_uri`**: the authorization endpoint accepts
//! arbitrary redirect URIs, allowing auth code / token theft.
//! - **Exposed `.well-known/openid-configuration`**: leaks all OAuth endpoints,
//! supported scopes, and signing keys — valuable recon for targeted attacks.
//! - **Token endpoint without client authentication**: the `/token` endpoint
//! accepts requests without `client_secret`, enabling public client abuse.
//! - **JWKS endpoint exposure**: signing keys are publicly accessible (expected
//! for validation, but can reveal algorithm mismatches).
use gossan_core::Target;
use reqwest::Client;
use secfinding::{Evidence, Finding, Severity};
/// Well-known OAuth/OIDC discovery paths.
const OIDC_DISCOVERY_PATHS: &[&str] = &[
"/.well-known/openid-configuration",
"/.well-known/oauth-authorization-server",
"/oauth/.well-known/openid-configuration",
"/auth/.well-known/openid-configuration",
"/realms/master/.well-known/openid-configuration", // Keycloak
"/.well-known/openid-configuration/",
];
/// Common authorization endpoint paths to probe for redirect_uri bypass.
const AUTH_ENDPOINT_PATHS: &[&str] = &[
"/authorize",
"/oauth/authorize",
"/oauth2/authorize",
"/auth/authorize",
"/connect/authorize",
"/oauth/auth",
"/api/oauth/authorize",
];
/// Probe for OAuth/OIDC misconfigurations.
pub async fn probe(client: &Client, target: &Target) -> anyhow::Result<Vec<Finding>> {
let Target::Web(asset) = target else {
return Ok(vec![]);
};
let base = asset.url.as_str().trim_end_matches('/');
let mut findings = Vec::new();
// ── OIDC discovery endpoint ──────────────────────────────────────────
for path in OIDC_DISCOVERY_PATHS {
let url = format!("{}{}", base, path);
let Ok(resp) = client.get(&url).send().await else {
continue;
};
if resp.status().as_u16() != 200 {
continue;
}
let Ok(body) = gossan_core::net::bounded_text(resp, 4 * 1024 * 1024).await else {
continue;
};
// Check if this is a real OIDC discovery document.
if !body.contains("authorization_endpoint") && !body.contains("issuer") {
continue;
}
let Ok(doc) = serde_json::from_str::<serde_json::Value>(&body) else {
continue;
};
// Extract useful endpoints from the discovery document.
let issuer = doc["issuer"].as_str().unwrap_or("unknown");
let auth_ep = doc["authorization_endpoint"].as_str();
let token_ep = doc["token_endpoint"].as_str();
let jwks_uri = doc["jwks_uri"].as_str();
let scopes: Vec<&str> = doc["scopes_supported"]
.as_array()
.map(|arr| arr.iter().filter_map(|v| v.as_str()).collect())
.unwrap_or_default();
gossan_core::try_push_finding(
crate::misconfig_finding(
target,
Severity::Info,
format!("OIDC discovery: {}", issuer),
format!(
"OpenID Connect discovery document at '{}' reveals the full OAuth \
infrastructure: authorization endpoint, token endpoint, JWKS URI, \
and {} supported scopes. This is standard behavior but provides \
valuable recon for further testing.",
url,
scopes.len()
),
)
.tag("oauth")
.tag("oidc")
.tag("discovery")
.evidence(Evidence::HttpResponse {
status: 200,
headers: vec![],
body_excerpt: Some(body.chars().take(500).collect::<String>().into()),
}),
&mut findings,
);
// ── Probe the authorization endpoint for open redirect ───────────
if let Some(auth_url) = auth_ep {
let evil_redirect = "https://evil-oauth-redirect.santh.io/callback";
let probe_url = format!(
"{}?response_type=code&client_id=gossan_probe&redirect_uri={}&scope=openid",
auth_url,
urlencoding::encode(evil_redirect)
);
if let Ok(resp) = client.get(&probe_url).send().await {
let status = resp.status().as_u16();
// If it redirects to our evil URI without error, redirect_uri is not validated.
if status == 302 || status == 303 {
if let Some(loc) = resp.headers().get("location") {
if let Ok(loc_str) = loc.to_str() {
if loc_str.contains("evil-oauth-redirect") {
gossan_core::try_push_finding(
crate::misconfig_finding(
target,
Severity::Critical,
"OAuth redirect_uri not validated — authorization code theft",
format!(
"The OAuth authorization endpoint at '{}' accepted \
an arbitrary redirect_uri ('{}') without validation. \
An attacker can steal authorization codes by redirecting \
the victim to their own server after authentication.",
auth_url, evil_redirect
),
)
.tag("oauth")
.tag("open-redirect")
.tag("critical")
.evidence(Evidence::HttpResponse {
status,
headers: vec![("Location".into(), loc_str.into())],
body_excerpt: None,
})
.exploit_hint(format!(
"# Redirect victim to:\\n{}",
probe_url
)),
&mut findings,
);
}
}
}
}
}
}
// ── Probe JWKS endpoint ──────────────────────────────────────────
if let Some(jwks_url) = jwks_uri {
if let Ok(resp) = client.get(jwks_url).send().await {
if resp.status().as_u16() == 200 {
if let Ok(jwks_body) = gossan_core::net::bounded_text(resp, 4 * 1024 * 1024).await {
if let Ok(jwks) = serde_json::from_str::<serde_json::Value>(&jwks_body) {
let key_count = jwks["keys"]
.as_array()
.map(|arr| arr.len())
.unwrap_or(0);
// Check for weak algorithms (none, HS256 with exposed key).
let algorithms: Vec<&str> = jwks["keys"]
.as_array()
.map(|arr| {
arr.iter()
.filter_map(|k| k["alg"].as_str())
.collect()
})
.unwrap_or_default();
let has_symmetric = algorithms.iter().any(|a| a.starts_with("HS"));
if has_symmetric {
gossan_core::try_push_finding(
crate::misconfig_finding(
target,
Severity::High,
"JWKS exposes symmetric signing keys",
format!(
"The JWKS endpoint at '{}' lists {} keys including \
symmetric algorithms ({}). If the symmetric key \
material is exposed (not just the algorithm name), \
an attacker can forge JWTs.",
jwks_url,
key_count,
algorithms.join(", ")
),
)
.tag("oauth")
.tag("jwt")
.tag("cryptographic")
.evidence(Evidence::HttpResponse {
status: 200,
headers: vec![],
body_excerpt: Some(
jwks_body.chars().take(500).collect::<String>().into(),
),
}),
&mut findings,
);
}
}
}
}
}
}
// ── Probe token endpoint without client_secret ───────────────────
if let Some(token_url) = token_ep {
let params = [
("grant_type", "authorization_code"),
("code", "gossan_probe_invalid_code"),
("redirect_uri", "https://example.com/callback"),
("client_id", "gossan_probe"),
];
if let Ok(resp) = client.post(token_url).form(¶ms).send().await {
let status = resp.status().as_u16();
// If the error is about the code being invalid (not about missing client_secret),
// the token endpoint doesn't require client authentication.
if let Ok(body) = gossan_core::net::bounded_text(resp, 4 * 1024 * 1024).await {
if (status == 400 || status == 200)
&& (body.contains("invalid_grant")
|| body.contains("invalid_code")
|| body.contains("code_expired"))
&& !body.contains("invalid_client")
&& !body.contains("client_secret")
{
gossan_core::try_push_finding(
crate::misconfig_finding(
target,
Severity::Medium,
"OAuth token endpoint accepts public clients",
format!(
"The token endpoint at '{}' processed the request \
without requiring client_secret. The error was about \
the authorization code, not client authentication. \
This means any application can exchange codes without \
proving its identity. Use PKCE and/or require client_secret.",
token_url
),
)
.tag("oauth")
.tag("misconfiguration")
.evidence(Evidence::HttpResponse {
status,
headers: vec![],
body_excerpt: Some(body.chars().take(300).collect::<String>().into()),
}),
&mut findings,
);
}
}
}
}
// Only probe the first valid OIDC discovery path.
break;
}
// ── Fallback: probe common auth endpoints without discovery ───────────
if findings.is_empty() {
for path in AUTH_ENDPOINT_PATHS {
let url = format!("{}{}", base, path);
let Ok(resp) = client.get(&url).send().await else {
continue;
};
let status = resp.status().as_u16();
// If the endpoint exists (200 or redirect), it's worth noting.
if status == 200 || status == 302 || status == 303 {
gossan_core::try_push_finding(
crate::misconfig_finding(
target,
Severity::Info,
format!("OAuth endpoint detected: {}", path),
format!(
"HTTP {} from '{}' — an OAuth authorization endpoint is present. \
Test for redirect_uri validation, state parameter enforcement, \
and PKCE support.",
status, url
),
)
.tag("oauth")
.tag("discovery"),
&mut findings,
);
break;
}
}
}
Ok(findings)
}