Feature/sdsk 1692#32359
Conversation
add workflow and delete other workflow
edit build
Summary of ChangesHello @Vladislav-Orobinskiy, 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 integrates a new AI text classification feature, specifically a custom RuBERT model, into the system. It introduces a dedicated built-in tool provider and a Highlights
🧠 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. Changelog
Ignored Files
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new built-in tool for text classification using a custom RuBERT model, integrating with a local NeuroSD API. However, it introduces a significant Server-Side Request Forgery (SSRF) vulnerability. This is due to a user-configurable API URL in the tool's parameters and a global weakening of the SSRF proxy (Squid) configuration, which allows access to the host machine's IP address (172.17.0.1). This change affects all tools using the proxy, potentially exposing internal host services. Beyond this critical security concern, the implementation also presents opportunities to improve flexibility, robustness, and maintainability, specifically regarding hardcoded IP addresses, error handling, and internationalization for user-facing text.
| acl classification_api dst 172.17.0.1 | ||
| http_access allow allowed_domains | ||
| http_access allow classification_api |
There was a problem hiding this comment.
Allowing access to 172.17.0.1 (the default Docker bridge gateway/host IP) in the global SSRF proxy configuration significantly weakens the security posture of the entire Dify installation, enabling any tool using the proxy to reach host services and bypass SSRF protections. This hardcoded IP also reduces configuration flexibility. If access to the classification API is necessary via this IP, the ACL should be restricted to a specific port (e.g., 172.17.0.1:8000) instead of all safe ports. For improved flexibility, consider using an environment variable like ${CLASSIFICATION_API_HOST}.
| - name: api_url | ||
| type: string | ||
| required: false | ||
| default: http://172.17.0.1:8000 | ||
| label: | ||
| en_US: API URL | ||
| zh_Hans: API地址 | ||
| ru_RU: URL API | ||
| human_description: | ||
| en_US: The URL of the classification API (default uses Docker bridge gateway IP) | ||
| zh_Hans: 分类API的URL(默认使用Docker网桥网关IP) | ||
| ru_RU: URL API классификации (по умолчанию Docker bridge gateway IP) | ||
| form: form |
There was a problem hiding this comment.
The api_url parameter is user-configurable (form: form) and is used to construct the target URL for a network request. This allows an application developer to specify arbitrary URLs. When combined with the changes in the Squid proxy configuration (which now allows access to 172.17.0.1), this enables Server-Side Request Forgery (SSRF) against the host machine. An attacker could use this to probe internal services running on the host.
| api_url = tool_parameters.get("api_url", DEFAULT_API_URL).rstrip("/") | ||
| predict_url = f"{api_url}/predict" | ||
|
|
||
| try: | ||
| response = ssrf_proxy.post( | ||
| predict_url, | ||
| json={"text": text}, | ||
| headers={"Content-Type": "application/json"}, | ||
| timeout=CLASSIFICATION_TIMEOUT, | ||
| ) |
There was a problem hiding this comment.
The api_url parameter, which can be controlled by the user, is used here to construct predict_url without any validation. This URL is then passed to ssrf_proxy.post. Since the proxy configuration has been modified to allow the host IP 172.17.0.1, this tool can be used to perform SSRF attacks against the host machine.
| from core.tools.entities.tool_entities import ToolInvokeMessage | ||
| from core.tools.errors import ToolInvokeError | ||
|
|
||
| DEFAULT_API_URL = "http://172.17.0.1:8000" |
There was a problem hiding this comment.
Hardcoding the DEFAULT_API_URL makes the application less flexible and harder to configure in different environments. It's recommended to source this value from the application's configuration, for example, using an environment variable. This would improve maintainability. You could add a new variable to your dify_config and use it here.
| try: | ||
| error_detail = response.json().get("detail", response.text) | ||
| error_msg = f"{error_msg}: {error_detail}" | ||
| except Exception: |
There was a problem hiding this comment.
Catching a generic Exception is too broad and can mask other issues. It's better to catch a more specific exception. Since response.json() can raise a JSONDecodeError if the response is not valid JSON, you should catch that specifically. The import json statement is already present in the file.
| except Exception: | |
| except json.JSONDecodeError: |
| formatted_text = ( | ||
| f"Результат классификации:\n" | ||
| f"• Сервис: {service}\n" | ||
| f"• Тип: {type_name}" | ||
| ) |
There was a problem hiding this comment.
|
For 3rd party models please submit a plugin to this repo instead https://github.com/langgenius/dify-plugins/pulls |
Integration of custom RuBERT model for text classification