Skip to content

Commit 7c30ae7

Browse files
authored
chore: add checker to detect flask app running on insecure host (#147)
* chore: add checker to detect flask app running with host 0.0.0.0 Signed-off-by: Maharshi Basu <basumaharshi10@gmail.com> * chore: add test directives in test file Signed-off-by: Maharshi Basu <basumaharshi10@gmail.com> * chore: refine checker message to describe the problem better Signed-off-by: Maharshi Basu <basumaharshi10@gmail.com> --------- Signed-off-by: Maharshi Basu <basumaharshi10@gmail.com>
1 parent 2c08eec commit 7c30ae7

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Ref: https://owasp.org/Top10/A01_2021-Broken_Access_Control [OWASP A01:2021]
2+
3+
# <expect-error>
4+
app.run(host="0.0.0.0")
5+
6+
# <expect-error>
7+
app.run("0.0.0.0")
8+
9+
# OK
10+
foo.run("0.0.0.0")
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
language: py
2+
name: app-run-with-bad-host
3+
message: Running Flask with host 0.0.0.0 allows connections from any network interface, posing a security risk.
4+
category: security
5+
severity: warning
6+
7+
pattern: >
8+
(call
9+
function: (attribute
10+
object: (identifier) @app
11+
attribute: (identifier) @run)
12+
arguments: (argument_list
13+
(_)*
14+
[
15+
(keyword_argument
16+
name: (identifier) @host
17+
value: (string
18+
(string_content) @ip))
19+
20+
(string
21+
(string_content) @ip)
22+
]
23+
(_)*)
24+
(#eq? @app "app")
25+
(#eq? @run "run")
26+
(#eq? @host "host")
27+
(#eq? @ip "0.0.0.0")) @app-run-with-bad-host
28+
29+
30+
description: >
31+
Running a Flask application with the host set to 0.0.0.0 allows it to accept connections from any network interface, potentially exposing the server to the public internet. This can pose security risks, as unauthorized users may be able to access the application if proper authentication and firewall rules are not in place

0 commit comments

Comments
 (0)