Skip to content

fix(ts): fix TS SDK build + export encryption module (v3.3.0) — closes #1404 - #1409

Merged
imran-siddique merged 1 commit into
microsoft:mainfrom
imran-siddique:fix/ts-encryption-exports
Apr 24, 2026
Merged

fix(ts): fix TS SDK build + export encryption module (v3.3.0) — closes #1404#1409
imran-siddique merged 1 commit into
microsoft:mainfrom
imran-siddique:fix/ts-encryption-exports

Conversation

@imran-siddique

Copy link
Copy Markdown
Collaborator

Fixes TS build for TypeScript 6, replaces dropped noble randomBytes, bumps to v3.3.0 with encryption exports. Unblocks Azure/kars#29.

… (v3.3.0)

- Remove ignoreDeprecations: '6.0' from tsconfig.json (invalid in TS 6)
- Replace @noble/ciphers/utils.js randomBytes import with node:crypto
  webcrypto.getRandomValues (noble dropped randomBytes export)
- Bump version to 3.3.0 — encryption module (X3DH, MeshClient,
  SecureChannel, DoubleRatchet) now in published dist/

This unblocks Azure/kars#29 which depends on encryption exports.

Closes #1404

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the agent-mesh agent-mesh package label Apr 24, 2026
@imran-siddique
imran-siddique merged commit 7c255ea into microsoft:main Apr 24, 2026
69 of 80 checks passed
@github-actions github-actions Bot added the size/S Small PR (< 50 lines) label Apr 24, 2026
@imran-siddique
imran-siddique deleted the fix/ts-encryption-exports branch April 24, 2026 05:16
@github-actions

Copy link
Copy Markdown
🤖 AI Agent: security-scanner — Security Review for PR: fix(ts): fix TS SDK build + export encryption module (v3.3.0)

Security Review for PR: fix(ts): fix TS SDK build + export encryption module (v3.3.0)


1. Prompt Injection Defense Bypass

No changes in this PR directly relate to prompt injection or input sanitization mechanisms. The changes focus on cryptographic utilities and TypeScript build configurations.
Rating: 🔵 LOW


2. Policy Engine Circumvention

No policy evaluation logic or enforcement mechanisms are modified in this PR. The changes are isolated to cryptographic utilities and build configurations.
Rating: 🔵 LOW


3. Trust Chain Weaknesses

The PR modifies cryptographic random number generation by replacing @noble/ciphers/utils.js's randomBytes with a custom implementation using webcrypto.getRandomValues. While getRandomValues is a secure source of randomness, the following concerns arise:

  • Attack Vector: If webcrypto is not properly polyfilled or replaced in non-browser environments, it could lead to insecure randomness.
  • Fix: Add a runtime check to ensure webcrypto.getRandomValues is available and functioning securely. If unavailable, throw an error or provide a fallback to a secure random number generator.
if (!webcrypto || typeof webcrypto.getRandomValues !== 'function') {
  throw new Error("Secure random number generation is not available.");
}

Rating: 🟠 HIGH


4. Credential Exposure

No sensitive credentials or secrets are introduced or exposed in this PR.
Rating: 🔵 LOW


5. Sandbox Escape

The PR does not introduce any changes that could lead to a sandbox escape. The changes are limited to cryptographic utilities and TypeScript build configurations.
Rating: 🔵 LOW


6. Deserialization Attacks

No deserialization logic or changes to data parsing mechanisms are introduced in this PR.
Rating: 🔵 LOW


7. Race Conditions

No concurrent operations or time-of-check-to-time-of-use (TOCTOU) vulnerabilities are introduced in this PR.
Rating: 🔵 LOW


8. Supply Chain

The PR replaces the randomBytes function from @noble/ciphers/utils.js with a custom implementation using webcrypto.getRandomValues. While this avoids dependency on the @noble/ciphers utility for randomness, the following concerns arise:

  • Attack Vector: If webcrypto is not properly supported in all environments (e.g., older Node.js versions or certain runtime environments), this could lead to runtime errors or insecure randomness.
  • Fix: Ensure compatibility with all supported environments by documenting the minimum required Node.js version and testing the implementation across all supported platforms.

Additionally, the PR does not introduce any new dependencies, so risks related to dependency confusion or typosquatting are minimal.
Rating: 🟡 MEDIUM


Summary of Findings

  1. Trust Chain Weaknesses: 🟠 HIGH

    • Ensure webcrypto.getRandomValues is available and secure in all runtime environments. Add runtime checks and fallback mechanisms if necessary.
  2. Supply Chain: 🟡 MEDIUM

    • Document the minimum supported Node.js version and test the webcrypto implementation across all supported environments.

Recommendations

  1. Add a runtime check to verify the availability and security of webcrypto.getRandomValues. Provide a fallback mechanism or throw an error if unavailable.
  2. Document the minimum supported Node.js version in the package.json file and README to ensure users are aware of compatibility requirements.
  3. Perform thorough testing of the updated random number generation implementation across all supported environments to ensure secure and consistent behavior.

Final Rating: 🟠 HIGH

The primary concern is the potential for insecure randomness if webcrypto.getRandomValues is not properly supported or implemented in all runtime environments. Addressing this issue is critical to maintaining the security of the cryptographic operations in the library.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 AI Agent: code-reviewer

Review Summary

This pull request addresses compatibility issues with TypeScript 6, replaces the deprecated randomBytes function from @noble/ciphers/utils.js with a custom implementation using webcrypto.getRandomValues, and updates the package version to 3.3.0. It also exports the encryption module to unblock a dependent project.

While the changes are generally well-implemented, there are a few areas of concern, particularly around cryptographic operations and backward compatibility. Below are detailed comments and recommendations.


🔴 CRITICAL

  1. Insecure Random Number Generation

    • The replacement of @noble/ciphers/utils.js's randomBytes with a custom implementation using webcrypto.getRandomValues introduces a potential security risk if not handled carefully.
    • While webcrypto.getRandomValues is a cryptographically secure random number generator, the implementation should ensure that it is used consistently and correctly across all environments, including Node.js and browser contexts.
    • Recommendation: Add a runtime check to ensure that webcrypto is available and functional. If it is not, fail gracefully with an appropriate error message. Additionally, document the requirement for webcrypto in the SDK's README or documentation.
  2. Lack of Tests for randomBytes Replacement

    • The new randomBytes implementation is a critical part of cryptographic operations. However, there are no tests to verify its correctness or behavior in different environments.
    • Recommendation: Add unit tests to validate the behavior of the randomBytes function. Ensure it produces random values of the correct length and works as expected in all supported environments.

🟡 WARNING

  1. Potential Breaking Change in randomBytes Implementation

    • The replacement of @noble/ciphers/utils.js's randomBytes with a custom implementation may lead to subtle differences in behavior, especially if the old implementation had specific characteristics (e.g., entropy source, distribution) that are not replicated in the new implementation.
    • Recommendation: Clearly document this change in the release notes and communicate it to users of the SDK. Highlight any potential differences in behavior and provide guidance for migration if necessary.
  2. Version Bump to 3.3.0

    • The version bump from 3.2.2 to 3.3.0 suggests a minor version update. However, the change in the randomBytes implementation could be considered a breaking change, depending on how it is used by downstream consumers.
    • Recommendation: Consider whether this should be a major version bump (4.0.0) instead of a minor version bump, as it may affect backward compatibility.

💡 SUGGESTIONS

  1. Centralize randomBytes Implementation

    • The randomBytes function is defined twice (in ratchet.ts and x3dh.ts). This duplication increases the risk of inconsistencies and makes future maintenance harder.
    • Recommendation: Extract the randomBytes function into a shared utility module and import it where needed.
  2. Improve Documentation

    • The PR description mentions that the encryption module is now exported, but there is no mention of this in the code diff or any accompanying documentation updates.
    • Recommendation: Update the SDK documentation to reflect the new encryption module export. Include usage examples and any relevant details about the new functionality.
  3. Test Coverage for Encryption Modules

    • The ratchet.ts and x3dh.ts files contain critical cryptographic logic, but there is no indication in this PR that additional tests were added or updated to cover these changes.
    • Recommendation: Ensure that the encryption modules have comprehensive test coverage, including edge cases and failure scenarios.
  4. TypeScript Configuration

    • The tsconfig.json file removes the ignoreDeprecations option for TypeScript 6. While this is likely intentional, it could lead to warnings or errors if deprecated APIs are used in the codebase.
    • Recommendation: Audit the codebase for any usage of deprecated TypeScript APIs and address them proactively.
  5. Changelog Update

    • The PR does not include an update to the changelog to document the changes made in this release.
    • Recommendation: Update the changelog to include details about the TypeScript 6 compatibility fix, the randomBytes replacement, and the new encryption module export.

Summary of Actions

  • 🔴 Add runtime checks and documentation for webcrypto usage.
  • 🔴 Add unit tests for the new randomBytes implementation.
  • 🟡 Consider whether the version bump should be major instead of minor.
  • 💡 Centralize the randomBytes function in a shared utility module.
  • 💡 Update SDK documentation to reflect the new encryption module export.
  • 💡 Ensure comprehensive test coverage for encryption modules.
  • 💡 Audit the codebase for deprecated TypeScript APIs.
  • 💡 Update the changelog to document the changes.

Let me know if you need further clarification or assistance!

MohammadHaroonAbuomar pushed a commit to MohammadHaroonAbuomar/agt-acs that referenced this pull request Jun 1, 2026
… (v3.3.0) (microsoft#1409)

- Remove ignoreDeprecations: '6.0' from tsconfig.json (invalid in TS 6)
- Replace @noble/ciphers/utils.js randomBytes import with node:crypto
  webcrypto.getRandomValues (noble dropped randomBytes export)
- Bump version to 3.3.0 — encryption module (X3DH, MeshClient,
  SecureChannel, DoubleRatchet) now in published dist/

This unblocks Azure/kars#29 which depends on encryption exports.

Closes microsoft#1404

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-mesh agent-mesh package size/S Small PR (< 50 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant