Add security warning when dev server binds to non-localhost#6018
Closed
zinc-builds wants to merge 3 commits into
Closed
Add security warning when dev server binds to non-localhost#6018zinc-builds wants to merge 3 commits into
zinc-builds wants to merge 3 commits into
Conversation
added 3 commits
May 11, 2026 00:38
Warn users when Flask's development server is bound to a non-localhost address, which exposes the Werkzeug debugger to the network. The debugger allows arbitrary code execution and should never be exposed on untrusted networks. - Raises RuntimeWarning when host is not 127.0.0.1/localhost/::1 - Raises an additional RuntimeWarning when debug mode is also enabled - Uses warnings.warn() so the warning is visible but doesn't prevent the server from starting (existing behavior preserved)
Flask's test suite uses filterwarnings=['error'] in pyproject.toml, which causes RuntimeWarning to fail tests. Using logging.warning() preserves the security warning while avoiding test failures.
Member
|
Not needed IMHO, and I have a strong feeling that this PR is LLM-generated. |
Member
|
Have you ever run the dev server before? It shows a warning always, no need for another one. Do not submit LLM junk to projects. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
RuntimeWarningwhen Flask's development server is bound to a non-localhost address. The Werkzeug debugger allows arbitrary code execution when exposed to the network, yet many tutorials and quick-start guides instruct users to bind to0.0.0.0without warning them of the risks.Security Impact
Binding the Werkzeug development server to a non-localhost address while debug mode is enabled exposes the interactive debugger to the network. The debugger's PIN-protected console can execute arbitrary Python code. This change warns users when:
127.0.0.1,localhost, or::1)Implementation
warnings.warn()withRuntimeWarningso the warning is visible but doesn't prevent the server from startingstacklevel=2so the warning points to the user'sapp.run()call, not the internal implementationThis aligns with the Google Patch Rewards qualifying submissions: "Elimination of error-prone design patterns or library calls." Binding a debug-capable server to 0.0.0.0 without warnings is a well-known footgun that has led to real-world compromises.
kumquatChecklist
warningsmodule (no new dependencies)stacklevel