Skip to content

Commit 88ec816

Browse files
committed
Python: Extend InMemoryCollection filter attribute blocklist
1 parent 1b2f318 commit 88ec816

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

python/semantic_kernel/connectors/in_memory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ class InMemoryCollection(
516516
blocked_filter_attributes: ClassVar[set[str]] = {
517517
# Object introspection - can lead to class/module access
518518
"__class__",
519+
"__base__",
519520
"__bases__",
520521
"__mro__",
521522
"__subclasses__",

python/tests/unit/connectors/memory/test_in_memory.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,22 @@ def test_direct_mutating_method_call_remains_blocked(collection):
196196
collection._parse_and_validate_filter("lambda x: x.clear() or True")
197197

198198

199+
@mark.parametrize(
200+
"attr",
201+
[
202+
"__base__",
203+
"__bases__",
204+
"__class__",
205+
"__mro__",
206+
"__subclasses__",
207+
"__globals__",
208+
],
209+
)
210+
def test_blocked_dunder_attributes_rejected(collection, attr):
211+
with raises(VectorStoreOperationException, match=f"Access to attribute '{attr}' is not allowed"):
212+
collection._parse_and_validate_filter(f"lambda x: x.{attr}")
213+
214+
199215
async def test_valid_lambda_filter_with_get_method(collection):
200216
record1 = {"id": "1", "vector": [1, 2, 3, 4, 5]}
201217
record2 = {"id": "2", "vector": [5, 4, 3, 2, 1]}

0 commit comments

Comments
 (0)