CoolCMS API

AdvertScopeHintTrait

Extracts the "which advert" hint from the caller filters for the dedicated `myList` collection actions.

IMPORTANT: the hint is not proof of ownership and not an authorization decision. It only converts a shape: the front end calls findAll([...new EqualFilter('advertId', 12)...]) and the Api action needs advertId as a separate parameter to load the advert from the database and decide there (AdvertScopeGuardTrait::advertScopeAllows()). A forged hint makes the server return nothing; the value never becomes a permission on its way.

A hint is used instead of a new parameter through all layers, which would mean many new methods in four layers of two modules for a single int. The value the caller sends anyway is read where the bridge request is composed.

It fails closed on drift. When the caller renames the filter or changes its shape, the hint is null; the result is degradation, not a leak: AdvertStatistics:myList without advertId returns nothing and Response:myList falls back to the "my adverts" mode (the caller filter narrows the result to that advert anyway). Tests\Unit\Security\AdvertScopedCollectionTest checks that the hint matches the real filter shape of both callers.

Table of Contents

Methods

advertScopeHint()  : int|null

Methods

advertScopeHint()

protected static advertScopeHint(array<int, mixed>|null $filters[, string $field = 'advertId' ]) : int|null
Parameters
$filters : array<int, mixed>|null
$field : string = 'advertId'

field name in the caller filter; advertId for collections, advert for the follow button (FollowTrait filters by the association, not a scalar)

Return values
int|null
On this page

Search results