Repository navigation
feat: MCP tool-call receipt signing integration - #1510
Imran Siddique (imran-siddique) merged 2 commits into
Conversation
Implements an AgentMesh adapter that wraps MCP tool calls with Cedar policy evaluation and produces signed governance receipts. Components: - McpReceiptAdapter: Policy check → receipt creation → Ed25519 signing - GovernanceReceipt: Signed proof with JCS canonical JSON hashing - CedarPolicyEvaluator: Lightweight Cedar permit/forbid evaluation - ReceiptStore: In-memory audit trail with query capabilities Follows the template-agentmesh and mcp-trust-proxy integration patterns. Zero required dependencies; optional cryptography for Ed25519 signing. Includes: - 44 unit tests covering policy evaluation, signing/verification, tamper detection, and receipt store operations - Worked example with Cedar policy file - Quickstart script Closes microsoft#1501
|
Welcome to the Agent Governance Toolkit! Thanks for your first pull request. |
There was a problem hiding this comment.
🤖 AI Agent: code-reviewer
Review Summary
This PR introduces the McpReceiptAdapter for wrapping MCP tool calls with Cedar policy evaluation and governance receipt signing. The implementation is well-structured, aligns with existing patterns in the repository, and includes comprehensive test coverage. However, there are several areas of concern and opportunities for improvement, particularly around security, thread safety, and type safety.
🔴 CRITICAL: Security Issues
-
HMAC-SHA256 Fallback for Receipt Signing
- The fallback to HMAC-SHA256 when the
cryptographylibrary is unavailable is problematic. HMAC-SHA256 does not provide the same level of security guarantees as Ed25519 for non-repudiation. HMAC is symmetric, meaning the same key is used for signing and verification, which undermines the purpose of a cryptographic signature in this context. - Recommendation: Remove the HMAC-SHA256 fallback entirely. Instead, enforce the use of the
cryptographylibrary for Ed25519 signing. If the library is unavailable, raise an exception and fail securely.
- The fallback to HMAC-SHA256 when the
-
Error Handling in Receipt Signing
- The
sign_receiptmethod catches all exceptions (except Exception as exc) and logs an error, but it still proceeds to store the receipt with anerrorfield. This could lead to a false sense of security, as the receipt is stored even if it is not properly signed. - Recommendation: If signing fails, do not store the receipt. Instead, raise an exception or return an error to the caller.
- The
-
Policy Evaluation Fallback
- The
CedarPolicyEvaluatorfalls back to a custom inline parser if theagentmesh.governance.cedarmodule is unavailable. This inline parser is simplistic and may not handle complex Cedar policies correctly, leading to potential false negatives (security bypass). - Recommendation: Remove the inline fallback and make the
agentmesh.governance.cedarmodule a required dependency. If the module is unavailable, raise an exception and fail securely.
- The
-
Receipt Verification
- The
verify_receiptmethod logs a warning when attempting to verify HMAC-signed receipts but does not raise an error. This could lead to confusion or misuse. - Recommendation: Explicitly raise an exception when attempting to verify HMAC-signed receipts, as they cannot be verified without the private key.
- The
🟡 WARNING: Potential Breaking Changes
-
Default Deny Behavior
- The
CedarPolicyEvaluatorenforces a "default deny" policy if no explicit permit rule matches. While this is a secure default, it may break existing workflows if users expect a different default behavior. - Recommendation: Clearly document this behavior in the release notes and provide a configuration option to override the default deny behavior if needed.
- The
-
Python Version Requirement
- The
pyproject.tomlspecifiesrequires-python = ">=3.11". This is a breaking change for users on Python 3.9 or 3.10, which are listed as supported in the repository's README. - Recommendation: Update the README to reflect the new minimum Python version or adjust the
pyproject.tomlto maintain compatibility with Python 3.9 and 3.10.
- The
💡 Suggestions for Improvement
-
Thread Safety
- The
ReceiptStoreclass is not thread-safe, as it uses a standard list for storing receipts without any synchronization mechanisms. This could lead to race conditions in concurrent environments. - Recommendation: Use a thread-safe data structure (e.g.,
queue.Queue) or add thread locks to ensure safe concurrent access.
- The
-
Type Safety
- The
McpReceiptAdapter.govern_tool_callandMcpReceiptAdapter.govern_and_executemethods useOptional[Dict[str, Any]]fortool_args, but the type hint does not enforce immutability. Sincetool_argsis hashed, it should be immutable to prevent accidental modification. - Recommendation: Use
Optional[Mapping[str, Any]]instead ofOptional[Dict[str, Any]]to enforce immutability.
- The
-
Error Handling in
govern_and_execute- The
govern_and_executemethod logs errors during tool execution but does not propagate them. This could make debugging difficult. - Recommendation: Consider re-raising the exception after logging it, or provide an option to propagate the exception to the caller.
- The
-
Logging
- The logging messages are useful but could benefit from additional context, such as the
agent_didandtool_name, to make debugging easier. - Recommendation: Include more contextual information in log messages, especially for errors.
- The logging messages are useful but could benefit from additional context, such as the
-
Testing Edge Cases
- While the test coverage is comprehensive, it is unclear if edge cases (e.g., malformed policies, invalid Ed25519 keys, or corrupted receipts) are thoroughly tested.
- Recommendation: Add tests for edge cases, including:
- Invalid or malformed Cedar policies.
- Invalid or malformed Ed25519 keys.
- Corrupted or tampered receipts.
- Concurrent access to
ReceiptStore.
-
Documentation
- The documentation is clear and well-written, but it could benefit from additional details on certain topics.
- Recommendation: Expand the documentation to include:
- A detailed explanation of the security implications of using HMAC-SHA256 as a fallback.
- Examples of complex Cedar policies and their expected behavior.
- Guidance on how to handle errors during receipt signing and tool execution.
-
Backward Compatibility
- The
McpReceiptAdapterintroduces new functionality, but it is unclear if it integrates seamlessly with existing components in theagentmeshpackage. - Recommendation: Test the integration of
McpReceiptAdapterwith other components in theagentmeshpackage to ensure backward compatibility.
- The
Final Assessment
-
Strengths:
- Well-structured and modular implementation.
- Comprehensive test coverage for core functionality.
- Adherence to existing patterns in the repository.
-
Weaknesses:
- Security concerns with HMAC-SHA256 fallback and inline policy evaluation.
- Potential thread safety issues in
ReceiptStore. - Lack of clarity on backward compatibility with existing components.
By addressing the critical security issues and implementing the suggested improvements, this PR can be made more robust and secure.
🤖 AI Agent: security-scanner — Security Review of `feat: MCP tool-call receipt signing integration`Security Review of
|
| Finding | Rating | Recommendation |
|---|---|---|
| Prompt Injection Defense Bypass | 🔴 CRITICAL | Remove regex-based policy evaluation fallback. Enforce use of a robust Cedar parser. |
| Policy Engine Circumvention | 🟠 HIGH | Validate policy syntax and reject invalid policies. |
| Trust Chain Weaknesses | 🟠 HIGH | Validate signing key format and remove HMAC-SHA256 fallback. |
| Credential Exposure | 🟡 MEDIUM | Avoid logging sensitive data; use secure secrets management. |
| Sandbox Escape | 🔵 LOW | Sanitize and validate tool_fn and tool_args. |
| Deserialization Attacks | 🔵 LOW | Validate tool_args type before serialization. |
| Race Conditions | 🔵 LOW | Use thread-safe structures or synchronization for ReceiptStore. |
| Supply Chain Risks | 🟡 MEDIUM | Make cryptography a required dependency and pin versions. |
Final Recommendations
- Critical Fixes: Address the prompt injection defense bypass and policy engine circumvention issues immediately. These are critical vulnerabilities that could compromise the entire governance framework.
- High Priority: Strengthen the trust chain by enforcing proper key validation and removing the HMAC-SHA256 fallback.
- Medium Priority: Secure the signing key and dependencies to prevent credential exposure and supply chain attacks.
- Low Priority: Address sandbox escape, deserialization, and race condition issues to improve overall robustness.
This pull request introduces valuable functionality, but the identified security issues must be addressed to ensure the integrity and reliability of the governance framework.
…in deps - Remove symmetric HMAC-SHA256 fallback from sign_receipt; Ed25519 via cryptography is now required for signing - Sanitize exception messages in adapter logging to prevent key leakage - Pin cryptography>=41.0,<45.0 to mitigate dependency confusion
There was a problem hiding this comment.
🤖 AI Agent: code-reviewer
Pull Request Review: feat: MCP tool-call receipt signing integration
Summary
This PR introduces the McpReceiptAdapter for wrapping MCP tool calls with Cedar policy evaluation and governance receipt signing. The implementation includes a lightweight Cedar policy evaluator, a receipt signing mechanism using Ed25519 (with an HMAC-SHA256 fallback), and an in-memory receipt store for audit trails. The PR also includes comprehensive tests and examples.
Review Feedback
🔴 CRITICAL: Security Issues
-
Ed25519 Key Handling:
- The
signing_key_hexis passed as a plain string to theMcpReceiptAdapterconstructor. This approach is insecure as it exposes the private key in memory and logs. - Recommendation: Use a secure key management solution (e.g., Azure Key Vault, AWS KMS) to store and retrieve the private key securely. Avoid passing sensitive data as plain strings.
- The
-
HMAC-SHA256 Fallback:
- The fallback to HMAC-SHA256 for signing receipts in environments without the
cryptographylibrary is problematic. HMAC-SHA256 does not provide the same level of security as Ed25519 for non-repudiation. - Recommendation: Either make the
cryptographylibrary a required dependency or explicitly document the security trade-offs of using HMAC-SHA256. Consider raising an exception ifcryptographyis unavailable, as this could lead to a false sense of security.
- The fallback to HMAC-SHA256 for signing receipts in environments without the
-
Inline Cedar Policy Parsing:
- The inline Cedar policy evaluator uses regular expressions to parse and evaluate policies. This approach is error-prone and may lead to false negatives, allowing unauthorized actions.
- Recommendation: Remove the inline evaluator and make the
agentmesh.governance.cedardependency mandatory. If this is not feasible, ensure the inline evaluator is thoroughly tested with edge cases and complex policies.
-
ReceiptStore Thread Safety:
- The
ReceiptStoreclass is not thread-safe. The_receiptslist is directly modified without synchronization, which can lead to race conditions in concurrent environments. - Recommendation: Use thread-safe data structures (e.g.,
queue.Queue) or implement locking mechanisms (e.g.,threading.Lock) to ensure thread safety.
- The
-
Receipt Verification:
- The
verify_receiptfunction does not raise an exception or log detailed errors when verification fails. This could make debugging and auditing difficult. - Recommendation: Log detailed error messages when verification fails, including the reason for failure (e.g., invalid signature, missing fields).
- The
🟡 WARNING: Potential Breaking Changes
-
Backward Compatibility:
- The
McpReceiptAdapterintroduces a new feature but does not appear to modify existing APIs. However, the use ofagentmesh.governance.cedaras an optional dependency could lead to runtime errors if the library is not installed. - Recommendation: Clearly document the requirement for
agentmesh.governance.cedarin the README and consider adding a check during initialization to provide a more user-friendly error message.
- The
-
Python Version Requirement:
- The
pyproject.tomlspecifiesrequires-python = ">=3.11". This is a breaking change for users on Python 3.9 or 3.10. - Recommendation: If possible, test and support Python 3.9 and 3.10 to maintain compatibility with the project's stated stack.
- The
💡 Suggestions for Improvement
-
Logging:
- The logging in
CedarPolicyEvaluatorandMcpReceiptAdapteris minimal. For example, the inline evaluator does not log the policy evaluation result. - Recommendation: Add more granular logging for policy evaluation results, receipt creation, and signing/verification steps.
- The logging in
-
Error Handling:
- The
govern_and_executemethod captures exceptions during tool execution but does not propagate them. This could lead to silent failures. - Recommendation: Consider re-raising exceptions or providing an option to propagate them to the caller.
- The
-
Testing Coverage:
- While the PR mentions 44 unit tests, it is unclear if edge cases (e.g., malformed policies, invalid signatures, concurrent receipt store access) are covered.
- Recommendation: Add tests for edge cases, including:
- Invalid or malformed Cedar policies.
- Concurrent access to
ReceiptStore. - Receipt verification with tampered payloads or signatures.
-
Documentation:
- The README provides a good overview but lacks details on security trade-offs (e.g., HMAC-SHA256 fallback) and thread safety.
- Recommendation: Expand the README to include:
- Security considerations for key handling and signing.
- Thread safety guarantees and limitations of
ReceiptStore.
-
Type Safety:
- The
McpReceiptAdapterandGovernanceReceiptclasses lack type annotations for some arguments and return values (e.g.,tool_argsingovern_tool_call). - Recommendation: Add type annotations to all methods and attributes to improve type safety and developer experience.
- The
-
Canonical JSON Implementation:
- The
canonical_payloadmethod usesjson.dumpswithsort_keys=Trueandseparators=(",", ":")to generate canonical JSON. While this is a common approach, it may not fully comply with the JCS (JSON Canonicalization Scheme) standard. - Recommendation: Consider using a dedicated library for JCS-compliant canonical JSON serialization, such as
canonicaljson.
- The
-
ReceiptStore Scalability:
- The
ReceiptStoreis an in-memory store, which may not scale well for large numbers of receipts. - Recommendation: Consider adding support for pluggable storage backends (e.g., SQLite, Redis) for production use cases.
- The
-
Default Deny Behavior:
- The default deny behavior is a good security practice, but it might lead to unexpected results if users are unaware of it.
- Recommendation: Add a warning or log message when a policy evaluation results in a default deny decision.
Summary of Feedback
-
Critical Issues:
- 🔴 Secure key handling for Ed25519 private keys.
- 🔴 HMAC-SHA256 fallback introduces weaker security guarantees.
- 🔴 Inline Cedar policy evaluator is error-prone and may lead to false negatives.
- 🔴
ReceiptStoreis not thread-safe. - 🔴 Receipt verification lacks detailed error logging.
-
Warnings:
- 🟡 Potential backward compatibility issues due to Python 3.11 requirement.
- 🟡 Optional dependency on
agentmesh.governance.cedarcould cause runtime errors.
-
Suggestions:
- 💡 Improve logging for debugging and auditing.
- 💡 Enhance error handling in
govern_and_execute. - 💡 Add tests for edge cases and concurrency.
- 💡 Expand documentation to cover security and thread safety considerations.
- 💡 Use a JCS-compliant library for canonical JSON serialization.
- 💡 Consider scalable storage options for
ReceiptStore. - 💡 Log warnings for default deny decisions.
Please address the critical issues before merging this PR. The warnings and suggestions should also be considered to improve the robustness, security, and usability of the feature. Let me know if you need further clarification or assistance!
|
Addressed the critical findings from the automated security and code reviews in commit d384276:
Remaining findings (inline Cedar fallback, ReceiptStore thread safety, JCS compliance, pluggable backends) are either fail-safe by design (default deny) or out of scope for a first integration — happy to address in follow-up PRs if needed. All 44 tests continue to pass. |
Imran Siddique (imran-siddique)
left a comment
There was a problem hiding this comment.
Well-structured integration with 44 tests. Good that HMAC fallback was removed. Closes #1501.
539a7f3
into
microsoft:main
* feat: add MCP tool-call receipt signing integration (microsoft#1501) Implements an AgentMesh adapter that wraps MCP tool calls with Cedar policy evaluation and produces signed governance receipts. Components: - McpReceiptAdapter: Policy check → receipt creation → Ed25519 signing - GovernanceReceipt: Signed proof with JCS canonical JSON hashing - CedarPolicyEvaluator: Lightweight Cedar permit/forbid evaluation - ReceiptStore: In-memory audit trail with query capabilities Follows the template-agentmesh and mcp-trust-proxy integration patterns. Zero required dependencies; optional cryptography for Ed25519 signing. Includes: - 44 unit tests covering policy evaluation, signing/verification, tamper detection, and receipt store operations - Worked example with Cedar policy file - Quickstart script Closes microsoft#1501 * fix: address security review — remove HMAC fallback, sanitize logs, pin deps - Remove symmetric HMAC-SHA256 fallback from sign_receipt; Ed25519 via cryptography is now required for signing - Sanitize exception messages in adapter logging to prevent key leakage - Pin cryptography>=41.0,<45.0 to mitigate dependency confusion --------- Co-authored-by: Nishar <you@example.com>
The test-integrations matrix enumerates agentmesh-integrations packages explicitly. It was introduced in microsoft#226 (14 Mar 2026); mcp-receipt-governed was added six weeks later in microsoft#1510 and microsoft#1519 (27 Apr 2026) and was never enrolled, so no job has ever run its test suite. The module is not invisible to CI: the wheel-coherence job clean-venv imports mcp_receipt_governed from the agent-governance-toolkit-protocols umbrella wheel ("protocols import OK"). That import passes, which is part of why the missing test coverage was easy to miss. Signed-off-by: Arian Gogani <goganiarian@gmail.com>
Summary
Implements MCP tool-call receipt signing as a first-party AGT integration. Every MCP tool invocation optionally produces a signed governance receipt linking the Cedar policy decision to the tool call.
Closes #1501
Changes
AgentMesh Adapter (
agentmesh-integrations/mcp-receipt-governed/)McpReceiptAdapter— wraps MCP tool calls with Cedar policy evaluation and receipt signingGovernanceReceipt— signed proof of a governance decision (JCS canonical JSON, Ed25519)CedarPolicyEvaluator— lightweight Cedar permit/forbid evaluator (usesagentmesh.governance.cedarwhen available, inline fallback otherwise)ReceiptStore— in-memory audit trail with query by agent/tool/decisionExample (
examples/mcp-receipt-governed/)Quickstart (
examples/quickstart/mcp_receipts_in_60_seconds.py)Design Decisions
cryptographyextracryptographystill get signed receipts (with a warning)template-agentmeshandmcp-trust-proxystructureTesting
44 unit tests covering:
govern_and_executelifecycle (allowed executes, denied blocks, exceptions captured)ReceiptStorequery, export, stats, and shared store