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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// Copyright (c) 2026 Bountyy Oy. All rights reserved.
// This software is proprietary and confidential.
/**
* Bountyy Oy - Baseline Response Detector
* Detects sites that respond identically to all requests (false positive prevention)
*
* Many AWS/CDN/proxy sites return 200 OK for everything, causing false positives.
* This module tests if a site's behavior is consistent across different request types.
*
* @copyright 2026 Bountyy Oy
* @license Proprietary
*/
use crate::http_client::{HttpClient, HttpResponse};
use std::sync::Arc;
use tracing::debug;
/// Baseline detection result
#[derive(Debug, Clone)]
pub struct BaselineResult {
/// Whether the site appears to respond identically to all requests
pub is_static_responder: bool,
/// The baseline response (if static responder)
pub baseline_response: Option<HttpResponse>,
/// Similarity score (0.0 - 1.0, where 1.0 = identical responses)
pub similarity_score: f64,
}
pub struct BaselineDetector {
http_client: Arc<HttpClient>,
}
impl BaselineDetector {
pub fn new(http_client: Arc<HttpClient>) -> Self {
Self { http_client }
}
/// Test if a URL responds identically to different requests
///
/// Returns true if the site is a "static responder" (always same response)
pub async fn is_static_responder(&self, url: &str) -> BaselineResult {
// PREMIUM FEATURE: Baseline Detector requires Professional license
if !crate::license::is_feature_available("baseline_detector") {
return BaselineResult {
is_static_responder: false,
baseline_response: None,
similarity_score: 0.0,
};
}
// Send 3 different requests:
// 1. Normal request
// 2. Request with random parameter
// 3. Request with obviously invalid parameter
let normal_url = url.to_string();
let random_url = format!(
"{}{}param_{}=value_{}",
url,
if url.contains('?') { "&" } else { "?" },
uuid::Uuid::new_v4().to_string(),
uuid::Uuid::new_v4().to_string()
);
let invalid_url = format!(
"{}{}invalid_test_param_xyz=<script>alert(1)</script>",
url,
if url.contains('?') { "&" } else { "?" }
);
// Get responses
let response1 = match self.http_client.get(&normal_url).await {
Ok(r) => r,
Err(_) => {
return BaselineResult {
is_static_responder: false,
baseline_response: None,
similarity_score: 0.0,
};
}
};
let response2 = match self.http_client.get(&random_url).await {
Ok(r) => r,
Err(_) => {
return BaselineResult {
is_static_responder: false,
baseline_response: Some(response1.clone()),
similarity_score: 0.5,
};
}
};
let response3 = match self.http_client.get(&invalid_url).await {
Ok(r) => r,
Err(_) => {
return BaselineResult {
is_static_responder: false,
baseline_response: Some(response1.clone()),
similarity_score: 0.5,
};
}
};
// Compare responses
let sim_1_2 = Self::calculate_similarity(&response1, &response2);
let sim_1_3 = Self::calculate_similarity(&response1, &response3);
let sim_2_3 = Self::calculate_similarity(&response2, &response3);
let avg_similarity = (sim_1_2 + sim_1_3 + sim_2_3) / 3.0;
debug!(
"Baseline detection: similarity scores: 1-2={:.2}, 1-3={:.2}, 2-3={:.2}, avg={:.2}",
sim_1_2, sim_1_3, sim_2_3, avg_similarity
);
// If all responses are > 95% similar, it might be a static responder
// BUT we should check if it's a SPA (Single Page Application) first
let mut is_static = avg_similarity > 0.95;
// Check if it's a SPA - SPAs return the same HTML shell for all routes
// but the actual content is loaded dynamically via JavaScript
if is_static {
let body = response1.body.to_lowercase();
let is_spa = body.contains("id=\"app\"") || // Vue/React common
body.contains("id=\"root\"") || // React common
body.contains("ng-app") || // Angular
body.contains("data-v-") || // Vue scoped styles
body.contains("__nuxt") || // Nuxt.js
body.contains("__next") || // Next.js
body.contains("_app.js") || // Next.js
body.contains("vue.") || // Vue.js
body.contains("react.") || // React
body.contains("angular.") || // Angular
body.contains("/graphql") || // GraphQL endpoint reference
body.contains("apolloclient") || // Apollo GraphQL client
body.contains("__apollo"); // Apollo state
if is_spa {
debug!(
"SPA DETECTED: Site is a Single Page Application - not treating as static responder despite {:.1}% similarity",
avg_similarity * 100.0
);
is_static = false;
}
}
if is_static {
debug!(
"STATIC RESPONDER DETECTED: Site responds identically ({:.1}% similarity) to all requests",
avg_similarity * 100.0
);
}
BaselineResult {
is_static_responder: is_static,
baseline_response: Some(response1),
similarity_score: avg_similarity,
}
}
/// Compare two responses and test if they behave differently
///
/// Used to verify that a vulnerability actually causes a different response
pub fn responses_are_different(
response_a: &HttpResponse,
response_b: &HttpResponse,
threshold: f64,
) -> bool {
let similarity = Self::calculate_similarity(response_a, response_b);
similarity < threshold
}
/// Calculate similarity between two HTTP responses
///
/// Returns 0.0 (completely different) to 1.0 (identical)
fn calculate_similarity(response_a: &HttpResponse, response_b: &HttpResponse) -> f64 {
// Factor 1: Status code match (30% weight)
let status_similarity = if response_a.status_code == response_b.status_code {
1.0
} else {
0.0
};
// Factor 2: Body length similarity (30% weight)
let len_a = response_a.body.len() as f64;
let len_b = response_b.body.len() as f64;
let max_len = len_a.max(len_b);
let min_len = len_a.min(len_b);
let length_similarity = if max_len == 0.0 {
1.0
} else {
min_len / max_len
};
// Factor 3: Content similarity (40% weight)
let content_similarity =
Self::calculate_content_similarity(&response_a.body, &response_b.body);
(status_similarity * 0.30) + (length_similarity * 0.30) + (content_similarity * 0.40)
}
/// Calculate content similarity using character-level comparison
fn calculate_content_similarity(text_a: &str, text_b: &str) -> f64 {
if text_a.is_empty() && text_b.is_empty() {
return 1.0;
}
if text_a.is_empty() || text_b.is_empty() {
return 0.0;
}
// For performance, compare first 5000 characters
let sample_a = if text_a.len() > 5000 {
&text_a[..5000]
} else {
text_a
};
let sample_b = if text_b.len() > 5000 {
&text_b[..5000]
} else {
text_b
};
// Count matching characters in the same positions
let matches = sample_a
.chars()
.zip(sample_b.chars())
.filter(|(a, b)| a == b)
.count();
let max_len = sample_a.len().max(sample_b.len());
if max_len == 0 {
1.0
} else {
matches as f64 / max_len as f64
}
}
/// Extract evidence from response for vulnerability reporting
pub fn extract_evidence(
response: &HttpResponse,
evidence_type: &str,
max_length: usize,
) -> String {
match evidence_type {
"headers" => {
format!("Response Headers:\n{:#?}", response.headers)
}
"body_snippet" => {
let snippet = if response.body.len() > max_length {
format!("{}... [truncated]", &response.body[..max_length])
} else {
response.body.clone()
};
format!("Response Body:\n{}", snippet)
}
"status" => {
format!("Status Code: {}", response.status_code)
}
"full" => {
let body_snippet = if response.body.len() > max_length {
format!("{}... [truncated]", &response.body[..max_length])
} else {
response.body.clone()
};
format!(
"Status: {}\nHeaders: {:#?}\nBody:\n{}",
response.status_code, response.headers, body_snippet
)
}
_ => String::new(),
}
}
}
// UUID generation
mod uuid {
use rand::Rng;
pub struct Uuid;
impl Uuid {
pub fn new_v4() -> Self {
Self
}
pub fn to_string(&self) -> String {
let mut rng = rand::rng();
format!(
"{:08x}-{:04x}-{:04x}-{:04x}-{:012x}",
rng.random::<u32>(),
rng.random::<u16>(),
rng.random::<u16>(),
rng.random::<u16>(),
rng.random::<u64>() & 0xffffffffffff
)
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::collections::HashMap;
#[test]
fn test_identical_responses() {
let resp1 = HttpResponse {
status_code: 200,
body: "Hello World".to_string(),
headers: HashMap::new(),
duration_ms: 100,
};
let resp2 = HttpResponse {
status_code: 200,
body: "Hello World".to_string(),
headers: HashMap::new(),
duration_ms: 105,
};
let similarity = BaselineDetector::calculate_similarity(&resp1, &resp2);
assert!(similarity > 0.99);
}
#[test]
fn test_different_responses() {
let resp1 = HttpResponse {
status_code: 200,
body: "Hello World".to_string(),
headers: HashMap::new(),
duration_ms: 100,
};
let resp2 = HttpResponse {
status_code: 404,
body: "Not Found".to_string(),
headers: HashMap::new(),
duration_ms: 50,
};
let similarity = BaselineDetector::calculate_similarity(&resp1, &resp2);
assert!(similarity < 0.5);
}
#[test]
fn test_responses_are_different() {
let resp1 = HttpResponse {
status_code: 200,
body: "Normal response".to_string(),
headers: HashMap::new(),
duration_ms: 100,
};
let resp2 = HttpResponse {
status_code: 200,
body: "SQL error: syntax error at position 5".to_string(),
headers: HashMap::new(),
duration_ms: 100,
};
assert!(BaselineDetector::responses_are_different(
&resp1, &resp2, 0.85
));
}
}