fix: upstream AzureClaw SDK patches + add GovernanceService proto (#557, #558)#559
Conversation
- mcp-proxy: shebang must be line 1 (TS18026) - copilot, mcp-server: typescript ^6.0.2 → ^5.7.0 (eslint <6.0.0) - NuGet: replace ESRP Sign+Release with NuGetCommand@2 push via NuGet.org service connection Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…crosoft#557, microsoft#558) Upstream bug fixes from AzureClaw vendored agentmesh-sdk: TypeScript SDK (identity.ts): - Add stripKeyPrefix() — strips ed25519:/x25519: prefixes before base64 decoding (fixes key decode failures with typed key formats) - Add safeBase64Decode() — convenience wrapper for safe prefix-aware decoding - Update fromJSON() to use safeBase64Decode() so serialized keys with type prefixes round-trip correctly - Export both functions from index.ts Proto (registration.proto): - Add GovernanceService with EvaluatePolicy, RecordAudit, GetTrustScore RPCs for language-agnostic governance integration - Add PolicyRequest, PolicyDecision, AuditEntry, AuditAck, TrustQuery, TrustScoreResult message types Tests: - 12 new tests in key-prefix.test.ts covering prefix stripping, safe decode, and fromJSON round-trip with prefixed keys Closes microsoft#557, Closes microsoft#558 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🤖 AI Agent: code-reviewer
Review Summary
This pull request introduces two major changes:
-
SDK Bug Fixes (#557): Fixes issues with key decoding in the
agentmesh-sdkby implementingstripKeyPrefixandsafeBase64Decodefunctions. These changes address issues with keys that include type prefixes (e.g.,ed25519:orx25519:). -
GovernanceService Proto (#558): Adds a new
GovernanceServicegRPC service definition for policy evaluation, audit recording, and trust score queries. This is a significant addition that enables language-agnostic integration for governance operations.
The changes are well-documented, and the new functionality is accompanied by comprehensive test coverage. However, there are a few areas that require attention, including potential security concerns, API design considerations, and opportunities for improvement.
🔴 CRITICAL
-
Key Prefix Handling - Security Implications:
- The
stripKeyPrefixfunction logs a warning when it encounters an unexpected prefix but still proceeds to strip the prefix and use the remaining key. This could lead to unintended behavior or security vulnerabilities if an attacker intentionally crafts a key with a misleading prefix. For example:In this case, the function would strip theconst result = stripKeyPrefix('malicious_prefix:actual_key', 'ed25519:');
malicious_prefixand useactual_key, potentially leading to a security bypass. - Recommendation: Instead of stripping unexpected prefixes, the function should throw an error or reject keys with unrecognized prefixes. This ensures that only explicitly allowed prefixes are processed.
- The
-
AuditEntry Hash Validation:
- The
AuditEntrymessage includes ahashandprevious_hashfield for tamper-evident logging. However, there is no indication in the PR that these hashes are validated or verified in the implementation. Without proper validation, the tamper-evident log could be compromised. - Recommendation: Ensure that the
hashandprevious_hashfields are cryptographically verified during theRecordAuditRPC. This should be explicitly documented in the proto file and implemented in the corresponding service logic.
- The
-
Trust Score Range Validation:
- The
TrustScoreResultmessage includes anoverall_scorefield with a range of0-1000. However, there is no validation or enforcement of this range in the proto definition or the implementation. - Recommendation: Add validation logic to ensure that the
overall_scorefalls within the specified range. This can be done using custom validation logic in the service implementation.
- The
🟡 WARNING
-
Breaking Changes in TypeScript SDK:
- The
AgentIdentity.fromJSONmethod now uses the newsafeBase64Decodefunction, which changes the behavior for keys with prefixes. While this is a bug fix, it could potentially break existing integrations if users were relying on the old behavior. - Recommendation: Clearly document this change in the release notes and consider bumping the major version of the SDK to indicate a breaking change.
- The
-
GovernanceService Proto - Backward Compatibility:
- Adding a new gRPC service (
GovernanceService) is a backward-compatible change. However, any future changes to this service (e.g., adding new fields to messages or modifying RPC methods) could introduce breaking changes. - Recommendation: Follow best practices for proto evolution, such as using reserved field numbers for removed fields and avoiding changes to existing field numbers or types.
- Adding a new gRPC service (
💡 SUGGESTIONS
-
Improved Error Handling in
stripKeyPrefix:- Instead of logging a warning for unexpected prefixes, consider returning an error or throwing an exception. This would make the function's behavior more predictable and reduce the risk of security issues.
- Example:
if (!keyStr.startsWith(expectedPrefix)) { throw new Error(`Unexpected key prefix. Expected '${expectedPrefix}'`); }
-
Test Coverage for Edge Cases:
- While the test suite is comprehensive, consider adding tests for the following edge cases:
- Keys with multiple colons (e.g.,
ed25519:x25519:AAAA). - Extremely long or malformed keys.
- Empty or null
contextmaps inPolicyRequest.
- Keys with multiple colons (e.g.,
- While the test suite is comprehensive, consider adding tests for the following edge cases:
-
Documentation for GovernanceService:
- The
GovernanceServiceproto is well-documented, but additional documentation should be provided for developers integrating with this service. For example:- Examples of valid
PolicyRequestandAuditEntrymessages. - Explanation of how
TrustScoreDimensionsis calculated and used.
- Examples of valid
- The
-
Thread Safety in GovernanceService:
- If the
GovernanceServiceimplementation involves shared state (e.g., for the audit log or trust score calculations), ensure that proper synchronization mechanisms are in place to avoid race conditions. - Recommendation: Use thread-safe data structures or synchronization primitives (e.g., locks) to manage shared state.
- If the
-
Consider Using a More Secure Base64 Decoder:
- The
safeBase64Decodefunction uses Node.js'sBuffer.frommethod for base64 decoding. While this is generally safe, consider using a library that explicitly handles edge cases like padding or invalid characters (e.g.,base64url).
- The
-
Policy Evaluation Context Validation:
- The
PolicyRequestmessage includes acontextmap for additional metadata. Ensure that the keys and values in this map are validated to prevent injection attacks or unexpected behavior in the policy engine.
- The
-
Logging Sensitive Information:
- The
console.warnstatements instripKeyPrefixmay inadvertently log sensitive information (e.g., key material). Avoid logging sensitive data or ensure that logs are sanitized.
- The
Final Assessment
- The PR addresses critical bugs and introduces valuable new functionality with the
GovernanceServiceproto. - However, there are critical security concerns related to key prefix handling and audit log validation that must be addressed before merging.
- Additionally, the potential breaking changes in the TypeScript SDK should be clearly communicated to users.
Action Items
- 🔴 Address the security concerns related to
stripKeyPrefixand audit log validation. - 🟡 Document the breaking changes in the TypeScript SDK and consider a major version bump.
- 💡 Implement the suggested improvements for error handling, test coverage, and documentation.
Once these issues are resolved, the PR will be ready for approval.
🤖 AI Agent: security-scanner — Security Review for PR: Upstream AzureClaw SDK Patches + GovernanceService ProtoSecurity Review for PR: Upstream AzureClaw SDK Patches + GovernanceService Proto1. Prompt Injection Defense BypassRating: 🔵 LOW No direct evidence of prompt injection vulnerabilities was found in this PR. The changes primarily focus on key prefix handling, base64 decoding, and the addition of a governance service proto. None of these changes involve user-controlled inputs being directly used in prompts. Recommendation:
2. Policy Engine CircumventionRating: 🟠 HIGH The Attack Vector:
Recommendation:
3. Trust Chain WeaknessesRating: 🔴 CRITICAL The Attack Vector:
Recommendation:
4. Credential ExposureRating: 🔵 LOW No evidence of credential exposure was found in the PR. The changes do not involve sensitive data handling or logging. Recommendation:
5. Sandbox EscapeRating: 🔵 LOW The PR does not introduce any changes related to container or process isolation. No evidence of sandbox escape vulnerabilities was found. Recommendation:
6. Deserialization AttacksRating: 🟠 HIGH The Attack Vector:
Recommendation:
7. Race ConditionsRating: 🔵 LOW No evidence of race conditions was found in the PR. The changes do not involve concurrent operations or time-of-check-to-time-of-use (TOCTOU) vulnerabilities. Recommendation:
8. Supply ChainRating: 🟠 HIGH The PR introduces a dependency on the official Attack Vector:
Recommendation:
Summary of Findings
Final Recommendation
|
Upstreams bug fixes from AzureClaw's vendored agentmesh-sdk and adds the GovernanceService proto for language-agnostic integration.
SDK Bug Fixes (#557)
AzureClaw vendors a patched agentmesh-sdk because keys with type prefixes (\�d25519:, \x25519:) fail to decode. These fixes allow AzureClaw to drop the vendor directory and depend on official releases.
GovernanceService Proto (#558)
Adds gRPC service definition for language-agnostic governance operations:
\\protobuf
service GovernanceService {
rpc EvaluatePolicy (PolicyRequest) returns (PolicyDecision);
rpc RecordAudit (AuditEntry) returns (AuditAck);
rpc GetTrustScore (TrustQuery) returns (TrustScoreResult);
}
\\
Tests
12 new tests covering prefix stripping, safe decode, and fromJSON round-trip with prefixed keys. All 149 TS SDK tests pass.
Closes #557, Closes #558