pub struct Scoped<T> { /* private fields */ }Expand description
A value that belongs to a tenant and cannot be read without proving the caller
owns it — the fail-closed object-level (OWASP API1 / BOLA) counterpart to
the advisory Principal::require_owns (ADR 0005).
Build it where the resource is loaded, from the record’s own tenant column:
// In the use case / handler, right after the load:
let note = Scoped::new("acme", NoteDto { title: "hi".into() });
// The ONLY way to reach the value is to pass the ownership check:
let caller = Principal::in_tenant("alice", "acme", ["notes.read"]);
let dto = note.owned_by(&caller).expect("same tenant");
assert_eq!(dto.title, "hi");There is no into_inner, no public field and no Deref: a handler that
forgets the check cannot reach the resource to return it, so the omission is a
compile error rather than a silent cross-tenant leak. #[must_use] means even
dropping it unused warns.
Implementations§
Source§impl<T> Scoped<T>
impl<T> Scoped<T>
Sourcepub fn new(tenant: impl Into<String>, value: T) -> Self
pub fn new(tenant: impl Into<String>, value: T) -> Self
Tags value as belonging to tenant. The caller passes the resource’s
own tenant (its database column, say), not the requester’s.
Sourcepub fn tenant(&self) -> &str
pub fn tenant(&self) -> &str
The tenant this value belongs to, readable without unwrapping — for a log
line or a metric label, never as a substitute for owned_by.