bug(pedo): missing tenant context bypasses isolation and foreign-tenant creates are accepted
Describe the bug
In chapter5/permission-embedded-data-objects/pedo/core/store.py, ObjectStore.get() permits a role-authorized caller with AccessContext.org_id=None or "" to read a tenant-owned object. The same role with a different, nonempty organization is correctly denied. ObjectStore.create() also accepts an explicitly supplied organization belonging to another tenant, and accepts references to another tenant's objects.
The existing hiring schema demonstrates both behaviors with the recruiter role. These are gaps in the data layer's tenant checks: the read guard requires both organization IDs to be truthy, while creation checks INSERT permissions without comparing the new object's organization with the caller's organization.
To Reproduce
Use the repository at c3352738f4b6fe42fe34e3cf6a79bcb424a133b8, Python 3.11, and psycopg2-binary. Run the following from the repository root. This uses the real ObjectStore pipeline and hiring schema, replacing only storage methods with an in-memory adapter; no PostgreSQL server or model API is required.
python -m pip install psycopg2-binarySave the following as repro_tenant.py in the repository root and run python repro_tenant.py:
import copy
import sys
from pathlib import Path
sys.path.insert(0, str(Path("chapter5/permission-embedded-data-objects").resolve()))
from pedo.core.models import AccessContext, DataObject
from pedo.core.store import ObjectStore, PermissionDeniedError
from pedo.scenarios.hiring import register_hiring_types
class MemoryStore(ObjectStore):
def _setup_db(self):
self.objects = {}
def _store_object(self, obj):
self.objects[obj.id] = copy.deepcopy(obj)
def _load_object(self, object_id):
return copy.deepcopy(self.objects.get(object_id))
store = MemoryStore("unused")
register_hiring_types(store)
store.create(DataObject(id="position", type_name="position", org_id="victim-org",
content={"status": "open"}),
AccessContext("system", role="system"))
for org in ("attacker-org", None, ""):
try:
store.get("position", AccessContext("eve", role="recruiter", org_id=org))
print(repr(org), "ALLOWED")
except PermissionDeniedError:
print(repr(org), "DENIED")
created = store.create(
DataObject(type_name="candidate", org_id="victim-org",
content={"status": "applied", "position_id": "position"}),
AccessContext("eve", role="recruiter", org_id="attacker-org"),
)
print("created in", created.org_id, "by", created.owner_id)Observed output on the base revision:
'attacker-org' DENIED
None ALLOWED
'' ALLOWED
created in victim-org by eveOn the base revision, a different organization is denied, both missing-organization cases are allowed, and the final create stores a victim-org candidate owned by eve. These behaviors were reproduced through the real pipeline using an in-memory storage adapter. The same creation path also accepts an attacker-org candidate referencing the victim-org position.
Expected behavior
A non-system caller must supply the matching organization to access a tenant-owned object. Omitting the organization must not turn a denied request into an allowed request. Creating an object in a tenant, or linking a new object to a tenant-owned parent/reference, must respect the same boundary.
Objects with an empty organization remain global and continue to use their permission rules. The existing system exception remains available for explicit cross-tenant operations.
Technical details / Root cause
_check_permission(), lines 328–333:obj.org_id and accessor.org_idskips isolation whenever the caller's organization is missing. The subsequent recruiter READ rule then grants access.create(), lines 194–225: top-level INSERT checks use type rules; an explicit foreignobj.org_idis retained. There is no target-tenant comparison before validators and persistence._validate_references(), lines 411–425: references are checked for existence and type, but not organization. Bothreferences[relationship]andcontent[relationship + "_id"]need tenant checks because validators can consume the content ID even whenreferencesoverrides it.
Impact
Verified with the original hiring schema: a recruiter context lacking an organization can read another tenant's records, and a recruiter can create records in a different tenant. Cross-tenant relationships are also accepted. This weakens the experiment's stated boundary for generated application code calling the stable data interface.
This report concerns the checks performed by ObjectStore; it does not claim that a deployed authentication layer lets arbitrary users choose their identity or role.
Related implementation / Existing behavior
The experiment README explicitly includes rejecting cross-tenant reads among its goals. test_tenant_isolation covers two different, nonempty organization IDs. It does not cover missing organization IDs or foreign-tenant creation.
Related contributions include #686 (initial PEDO implementation), #791 (live evaluator), #896 (metrics), and #1067 (timeout handling). They concern the same experiment but do not address these tenant-boundary cases. The prior issue/PR review did not identify a duplicate fix for this behavior.
Scope
The proposed fix covers missing tenant context, creation target organizations, and organizations of parents and declared references during creation. Ownership evaluation, update-time reference integrity, and deletion transactions are separate behaviors. Role-based permissions and the global-object/system policies continue to apply.
Environment
- Base:
mainatc3352738f4b6fe42fe34e3cf6a79bcb424a133b8. - Local patch:
fix/pedo-tenant-isolation, commitab3a49d48d57a1bf5a105d5ea4306b94ab077105. - Windows, Python 3.11.7; PostgreSQL-backed
ObjectStorewith an in-memory storage adapter for verification. - No PostgreSQL server was exercised, and no paid model API was used.
Source: bojieli/ai-agent-book