fix(platform): a tenant erasure is confirmed only by the tenant's own id
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 5m23s
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 / Check (pull_request) Successful in 23m11s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-11-30 21:22:34 +01:00
1 parent ecfee6db6e
commit f765b1474e
2 files changed
+30 -4

No files matched your search

+28 -3
View File
@@ -250,14 +250,16 @@ pub async fn export(
/// `DELETE /api/v1/platform/tenants/{id}/data` — GDPR erasure: drops the
/// tenant database and removes its code from disk (clones, uploads, work
/// trees, blobs, runner artifacts). Requires `{"confirm": "<slug or id>"}`.
/// trees, blobs, runner artifacts). Requires `{"confirm": "<tenant id>"}`:
/// the same id as in the path, so a call can only erase the tenant it names
/// twice; anything else is refused with 400 before anything is touched.
pub async fn delete_data(
State(st): State<PlatformState>,
Path(tenant_id): Path<String>,
body: Option<Json<LifecycleBody>>,
) -> Result<Json<serde_json::Value>, StatusCode> {
let confirm = body.and_then(|Json(b)| b.confirm).unwrap_or_default();
if confirm.is_empty() {
let confirm = body.and_then(|Json(b)| b.confirm);
if !confirms_erasure(&tenant_id, confirm.as_deref()) {
return Err(StatusCode::BAD_REQUEST);
}
// Where the tenant's code lies on disk, read before its records go.
@@ -299,6 +301,12 @@ pub async fn delete_data(
})))
}
/// Whether `confirm` confirms erasing `tenant_id`: it must be that id,
/// exactly. A missing or empty value, or another tenant's id, does not.
fn confirms_erasure(tenant_id: &str, confirm: Option<&str>) -> bool {
!tenant_id.is_empty() && confirm == Some(tenant_id)
}
/// `POST /api/v1/platform/tenants/demo/reset` — drops and re-creates the
/// demo tenant database. With `{"seed": true}` it then re-seeds the bundled
/// demo targets and starts their scans, which is what the nightly reset of the
@@ -848,3 +856,20 @@ mod target_count_tests {
assert!(stages[0].contains_key("$match") && stages[1].contains_key("$group"));
}
}
#[cfg(test)]
mod erasure_tests {
use super::*;
#[test]
fn only_the_tenants_own_id_confirms_its_erasure() {
assert!(confirms_erasure("t-1", Some("t-1")));
assert!(!confirms_erasure("t-1", None));
assert!(!confirms_erasure("t-1", Some("")));
assert!(!confirms_erasure("t-1", Some("t-2")));
assert!(!confirms_erasure("t-1", Some("T-1")));
assert!(!confirms_erasure("t-1", Some(" t-1")));
assert!(!confirms_erasure("t-1", Some("yes")));
assert!(!confirms_erasure("", Some("")));
}
}
+2 -1
View File
@@ -13,7 +13,8 @@ What Prüfwerk keeps about a target, where, and when it is removed.
Deleting a target (`DELETE /api/v1/targets/{id}`, or **Delete** on the
targets page) removes its records and its files. Erasing a tenant
(`DELETE /api/v1/platform/tenants/{id}/data`, confirmed) drops its database
(`DELETE /api/v1/platform/tenants/{id}/data` with `{"confirm": "<tenant id>"}`,
the same id as in the path) drops its database
and removes every file listed above; the response says how many paths were
removed and how many could not be. Only paths inside the two configured base
directories are ever removed.