fix(backend): reject foreign documentIds on submit and draft-sync (WP-68 F1)
submit and draft-sync took document ids straight from the request body with no ownership check: a caller who knew a foreign document's id could attach another citizen's upload to their own aanvraag (surfacing on the behandelaar's beoordeling screen, POSTed to OpenZaak as their zaakinformatieobject) and permanently block the victim's own delete by flipping Linked=true. ADR-0001 holds the FE has no authority; this trusted it anyway. Adds DocumentStore.ForeignIds(ids, owner) and calls it from both write paths before any write, 400 ProblemDetails on a mismatch. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -96,6 +96,22 @@ public static class DocumentStore
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Which of the given ids do NOT resolve to a document owned by <paramref name="owner"/>
|
||||
/// (unknown id or owned by someone else) — named for what it returns (the offending ids), so a
|
||||
/// caller can 400 with the specific ids rather than a bare boolean. Guards submit/draft-sync
|
||||
/// against a citizen attaching another citizen's upload to their own aanvraag.</summary>
|
||||
public static IReadOnlyList<string> ForeignIds(IEnumerable<string> documentIds, string owner)
|
||||
{
|
||||
var ids = documentIds.ToList();
|
||||
lock (_gate)
|
||||
{
|
||||
using var db = Db.Create();
|
||||
var owned = db.Documents.Where(d => ids.Contains(d.DocumentId) && d.Owner == owner)
|
||||
.Select(d => d.DocumentId).ToHashSet();
|
||||
return ids.Where(id => !owned.Contains(id)).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Persist the DRC url an OpenZaak upload (WP-51) registered for a document.</summary>
|
||||
public static void SetDrcUrl(string documentId, string drcUrl)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user