Skip to content

Conversation

@Oscaner
Copy link

@Oscaner Oscaner commented Jan 16, 2026

Add comprehensive SSL/TLS configuration capabilities to the plugin system:

  • Add environment variables for SSL verification control, custom CA certificates, and mTLS client authentication
  • Implement httpx.Client monkey patch to automatically apply SSL settings from environment configuration
  • Support base64-encoded certificate data (CA cert, client cert, and client key) to avoid file system dependencies
  • Enable SSL verification bypass for development/testing environments
  • Apply SSL patches at module import time to ensure all HTTP requests use configured settings

This allows plugins to communicate securely with services using custom certificates or mutual TLS authentication without code changes in individual HTTP client implementations.

Pull Request Checklist

Thank you for your contribution! Before submitting your PR, please make sure you have completed the following checks:

Compatibility Check

  • I have checked whether this change affects the backward compatibility of the plugin declared in README.md
  • I have checked whether this change affects the forward compatibility of the plugin declared in README.md
  • If this change introduces a breaking change, I have discussed it with the project maintainer and specified the release version in the README.md
  • I have described the compatibility impact and the corresponding version number in the PR description
  • I have checked whether the plugin version is updated in the README.md

Available Checks

  • Code has passed local tests
  • Relevant documentation has been updated (if necessary)

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Oscaner, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the security posture and flexibility of the plugin system by integrating comprehensive SSL/TLS configuration capabilities for outgoing HTTP requests. It allows users to configure certificate verification, custom CA certificates, and mutual TLS authentication through environment variables, which are then automatically applied to all httpx requests via a monkey patch. This change enables secure communication with diverse services without requiring modifications to individual plugin code, streamlining deployment in secure environments.

Highlights

  • Comprehensive SSL/TLS Support: Introduces robust SSL/TLS configuration capabilities for HTTP requests within the plugin system, enabling secure communication with various services.
  • Environment Variable Configuration: Allows control over SSL verification, custom CA certificates, and mutual TLS (mTLS) client authentication directly via environment variables.
  • Automatic SSL Application: Implements a monkey patch for httpx.Client to automatically apply SSL settings from environment configuration to all HTTP requests without requiring code changes in individual HTTP client implementations.
  • Base64 Certificate Support: Enables the use of base64-encoded certificate data for CA, client certificates, and client keys, reducing file system dependencies and simplifying deployment.
  • Development/Testing Bypass: Provides an option to bypass SSL verification for easier development and testing workflows, controlled by an environment variable.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Oscaner
Copy link
Author

Oscaner commented Jan 16, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces comprehensive SSL/TLS configuration for HTTP requests made via httpx, by monkey-patching httpx.Client. The changes allow configuring SSL verification, custom CA certificates, and mTLS through environment variables.

My review focuses on the security and implementation of the SSL context creation in python/dify_plugin/core/utils/ssl.py. I've identified a few areas for improvement:

  • A critical security enhancement to avoid writing CA certificates to disk by using the cadata parameter.
  • A high-severity security concern regarding the temporary storage of client private keys on the filesystem.
  • A recommendation to use more specific exception handling.

The new configuration options in DifyPluginEnv and the accompanying tests are well-implemented. Overall, this is a valuable feature for enhancing security.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces comprehensive SSL/TLS configuration for HTTP requests made via httpx, which is a great feature for enhancing security and connectivity in various environments. The implementation uses monkey-patching to apply settings globally, which is a clever approach to avoid changing all call sites.

My review focuses on improving the security and robustness of the new SSL utility module. I've identified a critical security vulnerability related to the handling of temporary files for certificates and private keys, and I've provided suggestions to mitigate this. I also have a few recommendations for improving exception handling and performance.

The addition of tests and example configuration is well done and makes the new feature easy to understand and verify.

Add comprehensive SSL/TLS configuration capabilities to the plugin system:

- Add environment variables for SSL verification control, custom CA certificates, and mTLS client authentication
- Implement httpx.Client monkey patch to automatically apply SSL settings from environment configuration
- Support base64-encoded certificate data (CA cert, client cert, and client key) to avoid file system dependencies
- Enable SSL verification bypass for development/testing environments
- Apply SSL patches at module import time to ensure all HTTP requests use configured settings

This allows plugins to communicate securely with services using custom certificates or mutual TLS authentication without code changes in individual HTTP client implementations.
… of temp file

Refactor SSL context creation to use in-memory certificate loading via
cadata parameter instead of writing to a temporary file. This simplifies
the code by removing file I/O operations and temporary file cleanup,
improving performance and reducing potential issues with file system
access.
…decoding

Import binascii module and catch specific binascii.Error instead of broad Exception when decoding base64 certificate data. This improves error handling specificity and follows best practices for exception handling by catching only the expected error type from base64.b64decode().
Enhance security of temporary SSL certificate and key file handling by:
- Setting restrictive file permissions (0o600) immediately after creation
- Using auto-delete temporary files to ensure cleanup
- Adding explicit flush() calls to guarantee data is written to disk
- Eliminating manual file cleanup code in favor of context manager
- Adding comprehensive security tests for file permissions and cleanup

This prevents potential security vulnerabilities where sensitive SSL keys
could be exposed with overly permissive file permissions or left on disk
after use. The ssl.SSLContext.load_cert_chain() reads file contents into
memory, allowing immediate deletion after loading.
Move DifyPluginEnv instantiation from function scope to module level
to avoid repeated object creation on every httpx.Client initialization.
This improves performance since environment-based SSL settings are
static and do not change during runtime.
@Oscaner
Copy link
Author

Oscaner commented Jan 16, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces valuable SSL/TLS configuration capabilities for HTTP requests by monkey-patching httpx. The approach is solid, particularly the secure handling of temporary files for mTLS. However, I've identified a critical issue and a high-severity issue that need to be addressed:

  1. Critical: The monkey patch is not applied to httpx.AsyncClient, which means asynchronous requests will not use the new SSL configuration. This could lead to inconsistent behavior and security risks.
  2. High: The integration tests for the patching logic are flawed and do not correctly verify that the configuration is being applied, reducing confidence in the implementation.

I have provided detailed comments and suggestions to resolve these issues. The other changes, including the new configuration options and the security-focused tests for temporary files, are well-implemented.

Extended SSL configuration patching to include httpx.AsyncClient in addition to the existing httpx.Client support. This ensures that both synchronous and asynchronous HTTP requests automatically apply SSL settings from environment variables (verification control, custom CA certificates, and mTLS).

Changes:
- Patched httpx.AsyncClient.__init__ to inject SSL configuration
- Added comprehensive tests for AsyncClient SSL behavior
- Updated module documentation to reflect async client support
- Stored original AsyncClient.__init__ to enable proper patching

This fix is necessary because the project uses gevent and async operations, which would otherwise bypass SSL configuration when using AsyncClient.
@Oscaner
Copy link
Author

Oscaner commented Jan 16, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a robust mechanism for configuring SSL/TLS for HTTP requests via environment variables, including support for custom CA and mTLS. The implementation via monkey-patching httpx is clever and minimizes impact on existing code. The addition of comprehensive tests, especially for security aspects like temporary file handling, is excellent.

My review includes a couple of points for improvement. I've identified a high-severity security and portability issue related to file permissions on non-POSIX systems. I've also suggested a medium-severity refactoring to improve the readability of the SSL context creation logic.

Overall, this is a well-executed feature that significantly enhances the plugin's security capabilities.

…patibility

Refactor SSL context creation by decoding all certificate data upfront
instead of checking boolean flags first. This reduces redundant decoding
operations and simplifies the logic flow.

Add Windows compatibility by conditionally applying chmod only on POSIX
systems, as Windows handles file permissions differently. This prevents
potential errors when running on Windows platforms.
@Oscaner
Copy link
Author

Oscaner commented Jan 16, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a robust mechanism for configuring SSL/TLS for all httpx requests by monkey-patching the client's __init__ methods. The changes are well-implemented, allowing for SSL verification control, custom CA certificates, and mTLS via environment variables. The use of base64-encoded data avoids filesystem dependencies, and the security of temporary files for mTLS keys is handled carefully. The accompanying tests are comprehensive, covering unit, integration, and security aspects. I have a couple of suggestions to improve code clarity and robustness.

…ate data

Add try-except block to catch UnicodeDecodeError when decoding CA certificate data and raise a more descriptive ValueError with context about the HTTP_REQUEST_NODE_SSL_CERT_DATA requirement. This provides clearer feedback when non-UTF-8 data is provided instead of allowing the error to propagate uncaught.

Also refactor client certificate/key file writing to use a loop for reduced code duplication, and add test case to verify proper error handling for invalid UTF-8 encoded certificate data.
@Oscaner
Copy link
Author

Oscaner commented Jan 16, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a well-designed and thoroughly tested feature for SSL/TLS configuration via environment variables. The approach of monkey-patching httpx at import time is clever and provides a seamless experience for plugin developers. The code quality is high, with excellent test coverage that includes functionality, edge cases, and security considerations. I've included a couple of minor suggestions to further improve code clarity in a security-sensitive area and enhance test suite portability.

…IX test guard

- Extract file path into separate variable in SSL context creation loop
- Use explicit path variable for os.chmod instead of file.name
- Add pytest skipif decorator to skip permissions test on non-POSIX systems
- Improve code clarity and maintain consistent permission handling across platforms

This change makes the temporary file permission setting more explicit and ensures tests only run on systems where chmod permissions work as expected.
@Oscaner
Copy link
Author

Oscaner commented Jan 17, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces comprehensive SSL/TLS configuration for HTTP requests by monkey-patching httpx. The implementation is robust, covering custom CA certificates and mTLS, and is backed by an excellent set of tests that validate functionality, edge cases, and security aspects like temporary file handling. The changes are well-structured and the new configuration options are clearly documented. I have a couple of minor suggestions to improve code clarity and test precision, but overall this is a high-quality contribution.

Comment on lines +101 to +108
for file, data, path in [
(cert_file, client_cert_data, cert_file.name),
(key_file, client_key_data, key_file.name),
]:
if os.name == "posix":
os.chmod(path, 0o600)
file.write(data)
file.flush() # Ensure data is written to disk
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For improved readability and conciseness, you can simplify this loop by removing the redundant path variable. The file path can be accessed directly from the file object using file.name.

            for file, data in [(cert_file, client_cert_data), (key_file, client_key_data)]:
                if os.name == "posix":
                    os.chmod(file.name, 0o600)
                file.write(data)
                file.flush()  # Ensure data is written to disk

pass

# Verify that chmod was called with 0o600 for both files
assert len(permissions_set) >= 2
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For a more precise test assertion, it's better to check for an exact number of calls. Since os.chmod is expected to be called exactly twice (once for the certificate and once for the key), using == 2 makes the test stricter and more accurate.

Suggested change
assert len(permissions_set) >= 2
assert len(permissions_set) == 2

@Oscaner
Copy link
Author

Oscaner commented Jan 19, 2026

@Mairuis Please review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant