Skip to content

Python: Default Dapr module allowlist to semantic_kernel prefix#13596

Merged
moonbox3 merged 8 commits intomicrosoft:mainfrom
moonbox3:dapr-default-module-allowlist
Mar 24, 2026
Merged

Python: Default Dapr module allowlist to semantic_kernel prefix#13596
moonbox3 merged 8 commits intomicrosoft:mainfrom
moonbox3:dapr-default-module-allowlist

Conversation

@moonbox3
Copy link
Copy Markdown
Collaborator

Motivation and Context

Follow-up to #13499. The previous PR added the allowed_module_prefixes parameter but defaulted it to None, which meant the module restriction was only active if developers discovered and configured it. Secure-by-default is the right posture here — restrict first, let developers widen as needed.

  • Change allowed_module_prefixes default from None to ("semantic_kernel.",) across Dapr runtime step loading
  • Non-SK step classes now require developers to explicitly add their module prefix (e.g. ("semantic_kernel.", "myapp.steps."))
  • Developers can pass None to opt out entirely, but the secure default is now enforced
  • The Dapr runtime code is experimental, so this is a non-breaking change per our stability guarantees

Contribution Checklist

@moonbox3 moonbox3 requested a review from a team as a code owner February 25, 2026 23:48
@moonbox3 moonbox3 added the python Pull requests for the Python Semantic Kernel label Feb 25, 2026
@moonbox3 moonbox3 self-assigned this Feb 26, 2026
@moonbox3
Copy link
Copy Markdown
Collaborator Author

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
processes
   step_utils.py520100% 
processes/dapr_runtime
   dapr_kernel_process_context.py41392%42, 44, 47
   dapr_process_info.py33487%35, 40, 50, 57
   dapr_step_info.py26196%51
processes/dapr_runtime/actors
   step_actor.py2656176%106, 109, 113–114, 126–128, 172–175, 193, 197, 201, 227, 235–236, 252–254, 257–262, 265–267, 274–275, 289, 293–295, 298–299, 316, 333–334, 339, 370–372, 392, 432, 444–452, 455, 458–462
TOTAL28165482982% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3835 23 💤 0 ❌ 0 🔥 1m 47s ⏱️

@moonbox3 moonbox3 enabled auto-merge February 26, 2026 03:34
Copilot AI review requested due to automatic review settings March 22, 2026 23:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes Python Dapr runtime step class loading secure by default by enforcing a default module allowlist of ("semantic_kernel.",) and updating tests and call sites accordingly.

Changes:

  • Introduces DEFAULT_ALLOWED_MODULE_PREFIXES = ("semantic_kernel.",) and makes it the default for get_step_class_from_qualified_name.
  • Propagates the new default allowlist through Dapr runtime conversion and execution paths (DaprStepInfo, DaprProcessInfo, DaprKernelProcessContext, StepActor).
  • Updates and expands unit tests to validate default blocking behavior and explicit opt out via allowed_module_prefixes=None.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
python/semantic_kernel/processes/step_utils.py Adds default allowlist constant and makes allowlist enforcement the default behavior in class loading.
python/semantic_kernel/processes/dapr_runtime/dapr_step_info.py Defaults step conversion to the secure allowlist constant.
python/semantic_kernel/processes/dapr_runtime/dapr_process_info.py Defaults process conversion to the secure allowlist constant and propagates it to nested steps.
python/semantic_kernel/processes/dapr_runtime/dapr_kernel_process_context.py Adds allowlist configuration to context and uses it when reconstructing process state from Dapr.
python/semantic_kernel/processes/dapr_runtime/actors/step_actor.py Defaults actor step loading to the secure allowlist constant.
python/tests/unit/processes/dapr_runtime/test_step_class_loading.py Updates tests for new default behavior and adds coverage for default allowlist behavior.
python/tests/unit/processes/dapr_runtime/test_dapr_kernel_process_context.py Updates fixture to pass an allowlist that permits the test step module.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread python/semantic_kernel/processes/step_utils.py Outdated
Comment thread python/semantic_kernel/processes/dapr_runtime/dapr_step_info.py
Comment thread python/semantic_kernel/processes/dapr_runtime/dapr_process_info.py
MAF Dashboard Bot and others added 2 commits March 23, 2026 01:26
…ing, update docstrings

- Change allowlist check from truthy to 'is not None' so empty sequence
  blocks all modules instead of silently allowing everything
- Tighten prefix matching to require segment boundaries when prefix does
  not end with a dot (prevents partial-segment matches like
  'semantic_kernel' matching 'semantic_kernel_evil')
- Update docstrings in step_utils.py, dapr_step_info.py, and
  dapr_process_info.py to reflect secure defaults and behavior of None
  vs empty sequence
- Add tests for empty allowlist, None allowlist, prefix segment boundary
  matching, and default allowlist behavior

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move imports of ProcessInvalidConfigurationException and
get_step_class_from_qualified_name to the top import block to fix
ruff E402 (module level import not at top of file).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Collaborator Author

@moonbox3 moonbox3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the CI/CD errors around code quality / pre-commit

Comment thread python/semantic_kernel/processes/step_utils.py
Break long ternary expression onto multiple lines to satisfy ruff's
formatting requirements.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread python/tests/unit/processes/dapr_runtime/test_step_class_loading.py
- Move pandas import to lazy loading in conftest.py to fix ImportError
- test_empty_allowlist_allows_all: Empty list [] should block all modules
  per the code logic (any() on empty iterable is False). Renamed to
  test_empty_allowlist_blocks_all and assert it raises.
- test_allowlist_prefix_matching: The code uses boundary-aware matching
  (exact match or prefix + '.'), so prefix 'test' does not match
  'test_step_class_loading'. Updated to test both the positive (exact
  match) and negative (non-boundary prefix) cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@moonbox3 moonbox3 disabled auto-merge March 24, 2026 02:18
@moonbox3 moonbox3 merged commit e0bd528 into microsoft:main Mar 24, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants