CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 4m25s
CI / Check (pull_request) Failing after 9m37s
The cleanup of an auto-register session deleted the test user in Prüfwerk's own Keycloak realm, through the agent's master-realm admin login, whatever identity provider the target used. It never ran only because the username was never recorded. - Cleanup acts only on admin access given for the session (`config.auth.cleanup`: Keycloak realm client, Auth0 M2M app, Okta token), sealed like the other session credentials and checked by the net guard; the agent's KEYCLOAK_ADMIN_* settings are gone. - The user is found by the session's own plus-addressed e-mail and deleted only when exactly one account carries exactly that address. The prompt now gives the LLM that exact address. - The test user is written to the stored session; a user that cannot be deleted is recorded as left behind and named in the report. - Firebase and Custom are not cleaned up (supersedes #17). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
175 lines
6.2 KiB
Rust
175 lines
6.2 KiB
Rust
use super::{html_escape, tool_category};
|
|
use compliance_core::models::pentest::{AuthMode, PentestConfig, PentestSession, TestUserRecord};
|
|
|
|
pub(super) fn scope(
|
|
session: &PentestSession,
|
|
target_name: &str,
|
|
target_url: &str,
|
|
date_str: &str,
|
|
completed_str: &str,
|
|
tool_names: &[String],
|
|
config: Option<&PentestConfig>,
|
|
) -> String {
|
|
let tools_table: String = tool_names
|
|
.iter()
|
|
.enumerate()
|
|
.map(|(i, t)| {
|
|
let category = tool_category(t);
|
|
format!(
|
|
"<tr><td>{}</td><td><code>{}</code></td><td>{}</td></tr>",
|
|
i + 1,
|
|
html_escape(t),
|
|
category,
|
|
)
|
|
})
|
|
.collect::<Vec<_>>()
|
|
.join("\n");
|
|
|
|
let engagement_config_section = if let Some(cfg) = config {
|
|
let mut rows = String::new();
|
|
rows.push_str(&format!(
|
|
"<tr><td>Environment</td><td>{}</td></tr>",
|
|
html_escape(&cfg.environment.to_string())
|
|
));
|
|
if let Some(ref app_type) = cfg.app_type {
|
|
rows.push_str(&format!(
|
|
"<tr><td>Application Type</td><td>{}</td></tr>",
|
|
html_escape(app_type)
|
|
));
|
|
}
|
|
let auth_mode = match cfg.auth.mode {
|
|
AuthMode::None => "No authentication",
|
|
AuthMode::Manual => "Manual credentials",
|
|
AuthMode::AutoRegister => "Auto-register",
|
|
};
|
|
rows.push_str(&format!("<tr><td>Auth Mode</td><td>{auth_mode}</td></tr>"));
|
|
if let Some(user) = &session.test_user {
|
|
rows.push_str(&test_user_row(user));
|
|
}
|
|
if !cfg.scope_exclusions.is_empty() {
|
|
let excl = cfg
|
|
.scope_exclusions
|
|
.iter()
|
|
.map(|s| html_escape(s))
|
|
.collect::<Vec<_>>()
|
|
.join(", ");
|
|
rows.push_str(&format!(
|
|
"<tr><td>Scope Exclusions</td><td><code>{excl}</code></td></tr>"
|
|
));
|
|
}
|
|
if !cfg.tester.name.is_empty() {
|
|
rows.push_str(&format!(
|
|
"<tr><td>Tester</td><td>{} ({})</td></tr>",
|
|
html_escape(&cfg.tester.name),
|
|
html_escape(&cfg.tester.email)
|
|
));
|
|
}
|
|
if let Some(ref ts) = cfg.disclaimer_accepted_at {
|
|
rows.push_str(&format!(
|
|
"<tr><td>Disclaimer Accepted</td><td>{}</td></tr>",
|
|
ts.format("%B %d, %Y at %H:%M UTC")
|
|
));
|
|
}
|
|
if let Some(ref branch) = cfg.branch {
|
|
rows.push_str(&format!(
|
|
"<tr><td>Git Branch</td><td>{}</td></tr>",
|
|
html_escape(branch)
|
|
));
|
|
}
|
|
if let Some(ref commit) = cfg.commit_hash {
|
|
rows.push_str(&format!(
|
|
"<tr><td>Git Commit</td><td><code>{}</code></td></tr>",
|
|
html_escape(commit)
|
|
));
|
|
}
|
|
format!("<h3>Engagement Configuration</h3>\n<table class=\"info\">\n{rows}\n</table>")
|
|
} else {
|
|
String::new()
|
|
};
|
|
|
|
format!(
|
|
r##"
|
|
<!-- ═══════════════ 2. SCOPE & METHODOLOGY ═══════════════ -->
|
|
<div class="page-break"></div>
|
|
<h2><span class="section-num">2.</span> Scope & Methodology</h2>
|
|
|
|
<p>
|
|
The assessment was performed using an AI-driven orchestrator that autonomously selects and
|
|
executes security testing tools based on the target's attack surface, technology stack, and
|
|
any available static analysis (SAST) findings and SBOM data.
|
|
</p>
|
|
|
|
<h3>Engagement Details</h3>
|
|
<table class="info">
|
|
<tr><td>Target</td><td><strong>{target_name}</strong></td></tr>
|
|
<tr><td>URL</td><td><code>{target_url}</code></td></tr>
|
|
<tr><td>Strategy</td><td>{strategy}</td></tr>
|
|
<tr><td>Status</td><td>{status}</td></tr>
|
|
<tr><td>Started</td><td>{date_str}</td></tr>
|
|
<tr><td>Completed</td><td>{completed_str}</td></tr>
|
|
<tr><td>Tool Invocations</td><td>{tool_invocations} ({tool_successes} successful, {success_rate:.1}% success rate)</td></tr>
|
|
</table>
|
|
|
|
{engagement_config_section}
|
|
|
|
<h3>Tools Employed</h3>
|
|
<table class="tools-table">
|
|
<thead><tr><th>#</th><th>Tool</th><th>Category</th></tr></thead>
|
|
<tbody>{tools_table}</tbody>
|
|
</table>"##,
|
|
target_name = html_escape(target_name),
|
|
target_url = html_escape(target_url),
|
|
strategy = session.strategy,
|
|
status = session.status,
|
|
date_str = date_str,
|
|
completed_str = completed_str,
|
|
tool_invocations = session.tool_invocations,
|
|
tool_successes = session.tool_successes,
|
|
success_rate = session.success_rate(),
|
|
)
|
|
}
|
|
|
|
/// The report row for the session's test user: deleted, or still registered
|
|
/// with the application and to be deleted by hand.
|
|
fn test_user_row(user: &TestUserRecord) -> String {
|
|
let email = html_escape(user.email.as_deref().unwrap_or("(unknown)"));
|
|
let state = match (&user.left_behind, user.cleaned_up) {
|
|
(Some(reason), _) => format!(
|
|
"<strong>Left behind</strong>: still registered with the application, \
|
|
delete it by hand ({})",
|
|
html_escape(reason)
|
|
),
|
|
(None, true) => "Deleted after the test".to_string(),
|
|
(None, false) => "Not deleted (cleanup was not requested)".to_string(),
|
|
};
|
|
format!("<tr><td>Test User</td><td><code>{email}</code> — {state}</td></tr>")
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test_user_tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn a_left_behind_test_user_is_named_with_its_reason() {
|
|
let user = TestUserRecord {
|
|
email: Some("pentest+1@mail.example.com".into()),
|
|
left_behind: Some("no admin access <given>".into()),
|
|
..Default::default()
|
|
};
|
|
let row = test_user_row(&user);
|
|
assert!(row.contains("pentest+1@mail.example.com"));
|
|
assert!(row.contains("Left behind"));
|
|
assert!(row.contains("no admin access <given>"));
|
|
}
|
|
|
|
#[test]
|
|
fn a_deleted_test_user_says_so() {
|
|
let user = TestUserRecord {
|
|
email: Some("pentest+1@mail.example.com".into()),
|
|
cleaned_up: true,
|
|
..Default::default()
|
|
};
|
|
assert!(test_user_row(&user).contains("Deleted after the test"));
|
|
}
|
|
}
|