Repository navigation
fix: '*' attribute dispatch only exposes public methods; bound obj_store - #23
Merged
Merged
Conversation
…bound obj_store attr_names='*' now means `public_attr`: a name is dispatchable only if it does not start with '_' and is defined on the object's class (or, for a module, in the module). Private helpers, dunders (__dict__, __init__, ...) and per-instance state are no longer reachable over HTTP. Explicit name lists are unchanged. attr_names also accepts a `(obj, attr_name) -> bool` predicate; the old behaviour is the explicit opt-in `attr_names=unsafe_any_attr`. Objects created through a class endpoint now live in a per-handler LRUObjStore (DFLT_OBJ_STORE_MAX_SIZE entries) instead of an unbounded module-global dict; a handler can pass its own `obj_store=` mapping. Also: an object that is falsy (e.g. an empty list) is no longer reported as missing. Refs #18 (item 2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed functions Refuses instance state that public_attr still let through (slots, dataclass and namedtuple fields, class defaults overwritten per instance, instance attributes shadowing methods), callables merely assigned as class attributes, and, on module endpoints, imported names and plain data (honours __all__). Non-string _attr_name/_obj_id now give InputError instead of a 500. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dict__ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #18 (item 2; item 1 landed in #20).
What changes
attr_names='*'now meanspublic_attr: a name is dispatchable only if it does not start with_and is a plain Python function,staticmethod,classmethodorpropertydefined on the object's class (or a base class) and not shadowed by the instance. For a module endpoint, only functions the module defines (or lists in__all__), never names it imports, nor plain data.Refused now:
_privatemethods, dunders (__dict__,__init__, ...), instance state (__dict__entries,__slots__, dataclass and namedtuple fields), callables merely assigned as class attributes (opener = open), builtin method descriptors (dict.clearon a dict subclass), and a module's imports (from os import listdir).examples/object_dispatch.pydoes).attr_namesalso accepts a predicate(obj, attr_name) -> bool.LRUObjStore(at mostDFLT_OBJ_STORE_MAX_SIZE = 1000, least recently used evicted) instead of an unbounded module-global dict. A handler can pass its ownobj_store=mapping. The module-globalobj_storeis gone; nothing in the fleet imported it._attr_name/_obj_idgives anInputErrorinstead of a 500; a dispatched method may have parameters namedobj/attr_name.Migration (one line)
To get the old "every attribute" behaviour back, for trusted clients only:
For an unbounded object store (old behaviour):
dict(endpoint=MyClass, attr_names=..., obj_store={}).Note that
'*'still exposes every public method, inherited ones included (e.g.MutableMapping'sclear/pop, pydantic'smodel_dump); for stores or objects holding secrets, list the names explicitly. This is documented inpublic_attrand pinned by a test.Adversarial review
A fresh Opus reviewer read the diff and the issue and tried to break it. First pass: SHIP-WITH-FIXES. It confirmed that the first version still leaked instance state through slots, dataclass and namedtuple fields and shadowed names; let a module endpoint reach anything it imported (it listed a directory through
from os import listdir) and its plain data; dispatched callable class attributes; and returned a 500 on unhashable names. All of these are fixed in 59bcae2, with tests. Second pass: SHIP. Its two low residuals are fixed in 6956169: dispatch internals are now positional-only, and the check reads the real instance__dict__. It deferred ownership of the class-endpoint objects and size bounds, now filed as #22.Checks
pytest py2http+ doctests: 55 passed.priv test-dependents py2http --transitive): py2http, extrude both pass.Follow-ups filed: #21 (JWT middleware options/algorithms), #22 (object ownership/size), i2mint/http2py#19 (client-side unpickling).
🤖 Generated with Claude Code