fix(pentest): delete test users only in the target's identity provider (#999) (#1002)
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 4s
CI / Deploy Docs (push) Successful in 1m9s
CI / Deploy MCP (push) Successful in 3m49s
CI / Deploy Dashboard (push) Successful in 4m55s
CI / Deploy Agent (push) Successful in 6m4s
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 4s
CI / Deploy Docs (push) Successful in 1m9s
CI / Deploy MCP (push) Successful in 3m49s
CI / Deploy Dashboard (push) Successful in 4m55s
CI / Deploy Agent (push) Successful in 6m4s
This commit was merged in pull request #1002.
This commit is contained in:
1 parent
396cb3cd39
commit
fad023e734
12 files changed
+813
-487
No files matched your search
@@ -86,6 +86,13 @@ pub async fn create_session(
|
||||
if let Err(e) = agent.net_guard.check_url(&config.app_url) {
|
||||
return Err((StatusCode::BAD_REQUEST, e.to_string()));
|
||||
}
|
||||
// The test-user cleanup talks to the target's identity provider, also
|
||||
// a tenant-chosen URL.
|
||||
if let Some(access) = &config.auth.cleanup {
|
||||
if let Err(e) = agent.net_guard.check_url(&access.base_url()) {
|
||||
return Err((StatusCode::BAD_REQUEST, e.to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
// Look up or auto-create DastTarget by app_url
|
||||
let target = match db
|
||||
@@ -187,35 +194,21 @@ pub async fn create_session(
|
||||
}
|
||||
}
|
||||
|
||||
// Pre-populate test user record for auto-register sessions
|
||||
if let Some(ref cfg) = session.config {
|
||||
if cfg.auth.mode == AuthMode::AutoRegister {
|
||||
let verification_email = cfg.auth.verification_email.clone();
|
||||
// Build plus-addressed email for this session
|
||||
let test_email = verification_email.as_deref().map(|email| {
|
||||
let parts: Vec<&str> = email.splitn(2, '@').collect();
|
||||
if parts.len() == 2 {
|
||||
format!("{}+{}@{}", parts[0], session_id_str, parts[1])
|
||||
} else {
|
||||
email.to_string()
|
||||
}
|
||||
});
|
||||
|
||||
// Detect identity provider from keycloak config
|
||||
let provider = if agent.config.keycloak_url.is_some() {
|
||||
Some(compliance_core::models::pentest::IdentityProvider::Keycloak)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
session.test_user = Some(compliance_core::models::pentest::TestUserRecord {
|
||||
username: None, // LLM will choose; updated after registration
|
||||
email: test_email,
|
||||
provider_user_id: None,
|
||||
provider,
|
||||
cleaned_up: false,
|
||||
});
|
||||
}
|
||||
// The test user an auto-register session registers, kept on the
|
||||
// stored session so cleanup and the report find it.
|
||||
if let Some(cfg) = &session.config {
|
||||
session.test_user = crate::pentest::cleanup::planned_test_user(cfg, &session_id_str);
|
||||
}
|
||||
if let (Some(sid), Some(test_user)) = (session.id, &session.test_user) {
|
||||
let record = mongodb::bson::to_bson(test_user)
|
||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
|
||||
db.pentest_sessions()
|
||||
.update_one(
|
||||
doc! { "_id": sid },
|
||||
doc! { "$set": { "test_user": record } },
|
||||
)
|
||||
.await
|
||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("DB error: {e}")))?;
|
||||
}
|
||||
|
||||
let initial_message = config
|
||||
|
||||
Reference in new issue
Block a user