fix: restrict debug endpoints to development mode#33428
fix: restrict debug endpoints to development mode#33428mango766 wants to merge 1 commit intolanggenius:mainfrom
Conversation
The /threads and /db-pool-stat endpoints expose internal server state (thread info, DB pool configuration) without any authentication. Wrap them with a dify_config.DEBUG check so they are only registered when the app is running in debug or testing mode. Co-Authored-By: Claude (claude-opus-4-6) <noreply@anthropic.com>
Summary of ChangesHello, 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 improves the application's security posture by ensuring that sensitive debug endpoints are not accessible in production. By gating these endpoints behind a development mode check, it prevents unauthorized access to internal system details, thereby reducing potential attack surfaces and safeguarding critical infrastructure information. 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
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 correctly restricts the debug endpoints /threads and /db-pool-stat to development and testing environments, which is an important security improvement. I have a couple of suggestions to improve the code's maintainability and readability within the affected functions.
| thread_list = [] | ||
| for thread in threads: | ||
| thread_name = thread.name | ||
| thread_id = thread.ident | ||
| is_alive = thread.is_alive() | ||
|
|
||
| return { | ||
| "pid": os.getpid(), | ||
| "thread_num": num_threads, | ||
| "threads": thread_list, | ||
| } | ||
| thread_list.append( | ||
| { | ||
| "name": thread_name, | ||
| "id": thread_id, | ||
| "is_alive": is_alive, | ||
| } | ||
| ) |
There was a problem hiding this comment.
| "checked_out_connections": engine.pool.checkedout(), # type: ignore | ||
| "overflow_connections": engine.pool.overflow(), # type: ignore | ||
| "connection_timeout": engine.pool.timeout(), # type: ignore | ||
| "recycle_time": db.engine.pool._recycle, # type: ignore |
There was a problem hiding this comment.
Accessing the protected member _recycle is fragile as it's an internal implementation detail of SQLAlchemy and could change in a future version, breaking this code. If you are using SQLAlchemy 1.4+, you should use the public attribute db.engine.pool.recycle. If a public API is not available for your version, consider adding a comment to explain why _recycle is used and which SQLAlchemy version this code relies on.
"recycle_time": db.engine.pool.recycle, # type: ignore
Pyrefly DiffNo changes detected. |
Wraps the
/threadsand/db-pool-statdebug endpoints in a development mode check so they're only registered when the app is running in debug or testing mode.These endpoints expose internal server state (thread info, DB pool config) without authentication, which is fine during development but shouldn't be available in production.
Closes #33427