Repository navigation
Python: fail closed when approval binding is unavailable (#8761) - #8780
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 4 commits intoSep 28, 2026
Conversation
Fail closed when approval_on_violation is enabled but no approval binding is available, instead of falling through to the permissive allow path. Add regression tests for microsoft#8761.
leilei3167
temporarily deployed
to
github-app-auth
September 26, 2026 22:23 — with
GitHub Actions
Inactive
leilei3167
temporarily deployed
to
github-app-auth
September 26, 2026 22:23 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The fallback can still be bypassed by an AttributeError when an unavailable binding is matched against an existing pending approval.
Review effort: Balanced
Findings: 1
What changed in this PR
Adds fail-closed handling when policy-violation approval binding cannot be established.
Changes:
- Blocks unresolved approval flows instead of allowing tool execution.
- Adds regression tests for unsafe and legacy identity bindings.
| File | Description |
|---|---|
python/packages/core/agent_framework/security.py |
Adds approval-mode fallback blocking. |
python/packages/core/tests/test_security.py |
Adds fail-closed regression coverage. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Only call _matches_pending_approval after _pending_record succeeds so a mocked or non-terminating unsafe-binding handler cannot hit None binding.
leilei3167
temporarily deployed
to
github-app-auth
September 27, 2026 04:16 — with
GitHub Actions
Inactive
leilei3167
temporarily deployed
to
github-app-auth
September 28, 2026 08:11 — with
GitHub Actions
Inactive
If _block_unsafe_approval_binding returns despite its NoReturn annotation, fail at the call site instead of continuing into the policy ladder.
leilei3167
temporarily deployed
to
github-app-auth
September 28, 2026 09:04 — with
GitHub Actions
Inactive
Contributor
Author
|
Evan Mattson (@moonbox3) the call site now raises MiddlewareFailure if |
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Sep 28, 2026
Eduard van Valkenburg (eavanvalkenburg)
left a comment
Member
There was a problem hiding this comment.
leilei3167 Looks good to me.
This branch was previously deployed
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.

Motivation & Context
When
PolicyEnforcementFunctionMiddlewareis configured withapproval_on_violation=True, a detected policy violation must not execute if an approval binding cannot be established. If_pending_recordfails and_block_unsafe_approval_bindingdoes not terminate the middleware chain, the ladder falls through withbinding is Noneandblock_on_violation=False, reaching the permissive allow path.Closes #8761
Description & Review Guide
approval_on_violationflows as a block (same asblock_on_violation) instead of logging(allowed)and callingcall_next().USER_IDENTITYsource without principals plus a fail-closed test when approval binding construction is unsafe.approval_on_violation=True._block_policy_violationis the right surface when approval binding fails, versus only raising from_block_unsafe_approval_binding.Contribution Checklist
Evidence
_block_unsafe_approval_bindingno-op):pytest packages/core/tests/test_security.py::TestPolicyEnforcementMiddleware::test_approval_on_violation_fail_closed_when_binding_record_failsfails with tool execution allowed.pytest packages/core/tests/test_security.py::TestPolicyEnforcementMiddleware::test_legacy_user_identity_violation_with_approval_does_not_execute_tool packages/core/tests/test_security.py::TestPolicyEnforcementMiddleware::test_approval_on_violation_fail_closed_when_binding_record_fails