pyrolab/drivers/sample.py:192:
class SelectiveSampleService(Service):
def __init__(self, items: List[Any] = []) -> None:
self._items = items
The default list is created once at function definition and shared by every instance that does not pass items. sort(), set_item() and the items setter all mutate it, so state leaks between instances.
This matters more than usual here because the class is a hosted service: under instance_mode="session" each client connection gets its own instance, all of which share the one default list; under "single" it is shared by definition. Either way, one client's set_item() is visible to the next.
It is also a sample service -- it is what users read when writing their own drivers, so the pattern propagates.
Fix:
def __init__(self, items: Optional[List[Any]] = None) -> None:
self._items = list(items) if items is not None else []
Found in a full-codebase audit at v0.4.0 (commit 1ce3146).
pyrolab/drivers/sample.py:192:The default list is created once at function definition and shared by every instance that does not pass
items.sort(),set_item()and theitemssetter all mutate it, so state leaks between instances.This matters more than usual here because the class is a hosted service: under
instance_mode="session"each client connection gets its own instance, all of which share the one default list; under"single"it is shared by definition. Either way, one client'sset_item()is visible to the next.It is also a sample service -- it is what users read when writing their own drivers, so the pattern propagates.
Fix:
Found in a full-codebase audit at v0.4.0 (commit 1ce3146).