Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(conversation): config encrypt decrypt payload transforms #3977

Open
wants to merge 4 commits into
base: next
Choose a base branch
from

Conversation

robstax
Copy link
Contributor

@robstax robstax commented Nov 14, 2024

This pull request addresses

there are use cases where we want to use conversation plugin, but not encryption/decryption, such as when iframed in another app that handles encrypt/decrypt

by making the following changes

there are two new config values to conditionally add encryption and decryption transforms. by default these are true.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

The following scenarios were tested

< ENUMERATE TESTS PERFORMED, WHETHER MANUAL OR AUTOMATED >
manual testing linking with web client
unit tests

I certified that

  • I have read and followed contributing guidelines

  • I discussed changes with code owners prior to submitting this pull request

  • I have not skipped any automated checks

  • All existing and new tests passed

  • I have updated the documentation accordingly


Make sure to have followed the contributing guidelines before submitting.

Summary by CodeRabbit

  • New Features

    • Introduced configuration options for enabling encryption and decryption on conversations.
    • Enhanced initialization logic for managing encryption and decryption transforms in the Conversation class.
  • Bug Fixes

    • Improved test coverage for payload transformations related to encryption and decryption.
  • Documentation

    • Updated unit tests to ensure consistent formatting and correct assertions for reactions.
  • Chores

    • Removed unnecessary imports related to encryption and decryption transforms in the main plugin file.

@robstax robstax requested review from a team as code owners November 14, 2024 23:36
Copy link

coderabbitai bot commented Nov 14, 2024

Walkthrough

The changes introduce new configuration properties for handling encryption and decryption in the @webex/internal-plugin-conversation package. Specifically, two boolean properties, includeDecryptionTransforms and includeEncryptionTransforms, are added to the configuration object. The Conversation class is modified to conditionally include these transforms during initialization based on the new properties. Additionally, unit tests are updated and expanded to cover the new functionality and ensure proper behavior regarding payload transformations.

Changes

File Change Summary
packages/@webex/internal-plugin-conversation/src/config.js Added includeDecryptionTransforms: true and includeEncryptionTransforms: true to the conversation object.
packages/@webex/internal-plugin-conversation/src/conversation.js Modified initialize() method to conditionally append encryption and decryption transforms based on the new config properties.
packages/@webex/internal-plugin-conversation/src/index.js Removed imports for encryptionTransforms and decryptionTransforms; adjusted transforms array accordingly.
packages/@webex/internal-plugin-conversation/test/unit/spec/conversation.js Added new test suite for payload transformations; updated existing tests for consistency and coverage.

Possibly related PRs

  • feat(core): add config for interceptors #3948: The changes in this PR enhance the configuration options for interceptors, which may relate to the new configuration properties for encryption and decryption in the main PR, as both involve modifying the configuration structure of the Webex SDK.

Suggested reviewers

  • chrisadubois
  • johnsoter13

Poem

🐇 In the realm of code where rabbits play,
New transforms hop in, brightening the way.
With decryption and encryption, they dance in delight,
Ensuring our messages stay safe and tight.
So let’s celebrate this change with cheer,
For secure conversations are finally here! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@robstax robstax changed the title Config encrypt decrypt feat(conversation): config encrypt decrypt payload transforms Nov 14, 2024
@robstax robstax added the validated If the pull request is validated for automation. label Nov 14, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (7)
packages/@webex/internal-plugin-conversation/src/config.js (2)

42-44: Fix incorrect documentation comment

The comment for includeEncryptionTransforms incorrectly mentions "decryption" instead of "encryption".

-     * config value to perform decryption on outbound conversations and activities
+     * config value to perform encryption on outbound conversations and activities
+     * @type {Boolean}

36-45: Consider grouping encryption-related configurations

The new properties are logically related to existing encryption settings like keepEncryptedProperties and decryptionFailureMessage, but they're separated in the config object. Consider grouping them together for better maintainability.

export default {
  conversation: {
    allowedInboundTags: {
      'webex-mention': ['data-object-type', 'data-object-id', 'data-object-url'],
    },
    allowedOutboundTags: {
      'webex-mention': ['data-object-type', 'data-object-id', 'data-object-url'],
    },
    // eslint-disable-next-line no-empty-function
    inboundProcessFunc: () => {},
    // eslint-disable-next-line no-empty-function
    outboundProcessFunc: () => {},
    allowedInboundStyles: [],
    allowedOutboundStyles: [],
    thumbnailMaxHeight: 960,
    thumbnailMaxWidth: 640,
+    // Encryption-related settings
+    includeDecryptionTransforms: true,
+    includeEncryptionTransforms: true,
    keepEncryptedProperties: false,
    decryptionFailureMessage: 'This message cannot be decrypted',
-    includeDecryptionTransforms: true,
-    includeEncryptionTransforms: true,
  },
};
packages/@webex/internal-plugin-conversation/src/index.js (3)

Line range hint 134-146: Ensure proper handling of outbound encryption

The outbound transform chain includes encryption steps that should be conditional based on the new configuration:

return ctx
  .transform('normalizeObject', object)
  .then(() => ctx.transform('encryptObject', object))
  .then(() => ctx.transform('encryptKmsMessage', object));

Consider refactoring this to:

  1. Check configuration before applying encryption transforms
  2. Make the encryption steps optional in the transform chain
  3. Document the behavior when encryption is disabled

Line range hint 147-161: Ensure proper handling of inbound decryption

Similar to the outbound transform, the inbound transform chain includes decryption that should be conditional:

return ctx
  .transform('decryptObject', object)
  .then(() => ctx.transform('normalizeObject', object));

Consider:

  1. Adding configuration checks before applying decryption
  2. Making decryption optional in the transform chain
  3. Documenting the behavior when decryption is disabled

Line range hint 1-316: Consider documenting the encryption/decryption behavior

The changes introduce conditional encryption/decryption, which is a significant architectural change. Consider:

  1. Adding JSDoc comments explaining the transform behavior with and without encryption/decryption
  2. Documenting any assumptions about external encryption/decryption handling
  3. Adding examples of how to properly configure and use the plugin with external encryption
packages/@webex/internal-plugin-conversation/test/unit/spec/conversation.js (1)

927-957: Enhance test coverage for transform verification.

While the test covers various configuration combinations, it could be improved by:

  1. Adding explicit assertions for empty transforms
  2. Verifying the exact transform count
  3. Adding assertions for transform order

Consider adding these additional assertions:

it.each([...])('%s should include the correct transforms based on configuration',
  async ({includeDecryptionTransforms, includeEncryptionTransforms, expectedTransforms}) => {
    setup({includeDecryptionTransforms, includeEncryptionTransforms});
    webex.trigger('ready');
    
    const actualTransforms = webex.config.payloadTransformer.transforms;
    
    // Verify transform count
    assert.lengthOf(actualTransforms, expectedTransforms.length, 
      'should have correct number of transforms');
    
    // Verify transform inclusion
    assert.isTrue(
      checkTransforms(actualTransforms, expectedTransforms),
      'should include expected transforms'
    );
    
    // If no transforms expected, verify array is empty
    if (expectedTransforms.length === 0) {
      assert.isEmpty(actualTransforms, 'should have no transforms');
    }
    
    // Verify transform order if both are included
    if (includeEncryptionTransforms && includeDecryptionTransforms) {
      assert.isTrue(
        actualTransforms.every((transform, index) => 
          transform.name === expectedTransforms[index].name
        ),
        'transforms should be in correct order'
      );
    }
  }
);
packages/@webex/internal-plugin-conversation/src/conversation.js (1)

82-89: Consider performance implications of transform initialization.

The current implementation concatenates arrays on every initialization. For better performance, consider using a more efficient approach.

Consider using a Set or maintaining a single array:

 initialize() {
   this.listenToOnce(this.webex, 'ready', () => {
+    const transforms = new Set(this.webex.config.payloadTransformer.transforms);
+    
+    if (this.config.includeDecryptionTransforms) {
+      decryptionTransforms.forEach(t => transforms.add(t));
+    }
+    if (this.config.includeEncryptionTransforms) {
+      encryptionTransforms.forEach(t => transforms.add(t));
+    }
+    
+    this.webex.config.payloadTransformer.transforms = Array.from(transforms);
   });
 },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f6017e0 and d420089.

📒 Files selected for processing (4)
  • packages/@webex/internal-plugin-conversation/src/config.js (1 hunks)
  • packages/@webex/internal-plugin-conversation/src/conversation.js (2 hunks)
  • packages/@webex/internal-plugin-conversation/src/index.js (1 hunks)
  • packages/@webex/internal-plugin-conversation/test/unit/spec/conversation.js (5 hunks)
🔇 Additional comments (7)
packages/@webex/internal-plugin-conversation/src/config.js (1)

36-45: Verify security implications of disabling encryption/decryption

The ability to disable encryption/decryption transforms could potentially create security vulnerabilities if not properly handled by the embedding application. Please ensure:

  1. The documentation clearly states the security implications
  2. There are appropriate warnings when these are disabled
  3. The application validates that alternative encryption is in place when disabled

Let's check for any existing security documentation or warnings:

packages/@webex/internal-plugin-conversation/src/index.js (3)

Line range hint 71-92: Review the conversation list decryption logic

The normalizeConversationListAndBindDecrypters transform binds a decrypt function to each item. This needs to respect the new configuration options for conditional decryption.

Let's verify the integration with config options:


Line range hint 1-316: Verify encryption/decryption transform dependencies

The file shows removal of encryption/decryption transform imports but still contains multiple references to these operations in the transform functions. We need to ensure these operations are properly handled when the transforms are conditionally included.

Let's verify the dependencies and usage:


316-316: Review transform registration order

The transforms array maintains a specific order of operations. Ensure that making encryption/decryption optional doesn't break dependencies between transforms.

Let's analyze transform dependencies:

packages/@webex/internal-plugin-conversation/test/unit/spec/conversation.js (2)

18-19: LGTM! Clean import additions.

The new imports for encryption and decryption transforms are properly placed and align with the new test suite requirements.


949-949: ⚠️ Potential issue

Fix misleading test description.

The test description "sets initFailed to true when collectPreauthCatalog errors" doesn't match what the test is actually verifying (transform inclusion based on configuration).

-      '%s sets initFailed to true when collectPreauthCatalog errors',
+      '%s should include the correct transforms based on configuration',

Likely invalid or redundant comment.

packages/@webex/internal-plugin-conversation/src/conversation.js (1)

28-29: Verify the security implications of the transform imports.

The imported encryption and decryption transforms are critical security components. We should ensure these modules are properly audited and tested.

✅ Verification successful

The imported transform modules are properly secured and tested

After analyzing the codebase, I can confirm that:

  1. Both encryption and decryption transforms are part of the internal plugin system with proper copyright and licensing.
  2. The transforms implement comprehensive security measures:
    • Proper key management and validation
    • Encrypted property handling
    • Secure error handling that doesn't leak sensitive information
  3. The code includes unit tests that verify the encryption behavior, particularly for sensitive operations.
  4. The transforms are used internally within the @webex namespace, limiting exposure.

The security implications of these imports are well-managed through:

  • Proper encapsulation within the internal plugin system
  • Comprehensive encryption/decryption transforms with proper key handling
  • Test coverage for critical security paths
  • Secure error handling patterns
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for security tests and audit logs for the transform modules

# Check for security tests
rg -A 5 "describe.*security|test.*security" "./encryption-transforms.js" "./decryption-transforms.js"

# Check for recent security audits in git history
git log -p --grep="security audit" -- "./encryption-transforms.js" "./decryption-transforms.js"

Length of output: 327


Script:

#!/bin/bash
# First, let's find the actual paths of these transform files
fd "encryption-transforms.js|decryption-transforms.js"

# Then let's check the content of these files for security-related code
rg -l "security|encrypt|decrypt" $(fd "encryption-transforms.js|decryption-transforms.js")

# Look for test files related to these transforms
fd "encryption.*test|decryption.*test"

Length of output: 889


Script:

#!/bin/bash
# Let's examine the content of the transform files and their tests
echo "=== Encryption Transforms ==="
cat packages/@webex/internal-plugin-conversation/src/encryption-transforms.js

echo -e "\n=== Decryption Transforms ==="
cat packages/@webex/internal-plugin-conversation/src/decryption-transforms.js

echo -e "\n=== Encryption Tests ==="
cat packages/@webex/internal-plugin-conversation/test/unit/spec/encryption-transforms.js

Length of output: 35484

Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-3977.d3m3l2kee0btzx.amplifyapp.com

.then(() => {
assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expected);
});
const expected = {items: [{id: recipientId, objectType: 'person'}]};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

most of these changes are just whitespace/formatting changes, except for the added new describe block

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d420089 and 499afa0.

📒 Files selected for processing (2)
  • packages/@webex/internal-plugin-conversation/src/conversation.js (2 hunks)
  • packages/@webex/internal-plugin-conversation/test/unit/spec/conversation.js (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/@webex/internal-plugin-conversation/src/conversation.js
🔇 Additional comments (3)
packages/@webex/internal-plugin-conversation/test/unit/spec/conversation.js (3)

18-19: LGTM: New imports for transform testing

The imports for encryption and decryption transforms are correctly placed and will be used in the new test suite.


43-44: LGTM: Improved test readability

The refactoring improves readability by extracting expected values into variables, making the tests more maintainable.

Also applies to: 57-58, 81-82, 95-96


905-959: LGTM: Well-structured test suite for payload transforms

The test suite is well-organized with:

  • Clear setup helper function
  • Utility function for transform verification
  • Comprehensive test coverage using parameterized tests
  • Clear assertions validating transform configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
validated If the pull request is validated for automation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant