Guard a read model with the authorization of the queries that read it - #29
Conversation
A slice declares as many read models as its behavior needs, and a query names the one it reads with its return type. The union guarding a read model was drawn from every query in the slice regardless, so a query on one read model decided the authorization of all the others. That fails in the permissive direction. AuthorizationRenderer collapses a union to AllowAnonymous as soon as one member is unguarded - correct for queries that genuinely read the same model - so one unguarded query on an unrelated read model published a guarded one to everyone. Attribute each query to the read model its return type names, and take the union over those alone. A read model that no declared query returns falls back to requiring an authenticated caller and reports it, rather than being left open; a slice declaring no query at all is unchanged.
Covers the multi-read-model slice end to end through the renderer - the guarded read model stays guarded beside another one's unguarded query - and the attribution rules on their own, including that the collapse to anonymous still holds for two queries reading the same read model.
The attribution keyA query names the read model it reads with its return type, so Why the unqueried read model does not simply render anonymousFiltering alone would have introduced a new permissive path: a read model whose slice declares queries only for its siblings would go from a (wrong, but closed) foreign guard straight to The pre-existing "a read model with no declared queries anywhere still gets an unguarded all/by-id pair the document never asked for" is untouched and out of scope here. Not this PR#20 ( Verification
|
Changed
[AllowAnonymous].Security
[AllowAnonymous]— the rendered application was more permissive than the document it came from.