Skip to content

Commit 45e72ac

Browse files
committed
avoid-bind-to-all-interfaces-go
1 parent ae5dc84 commit 45e72ac

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
id: avoid-bind-to-all-interfaces-go
2+
language: go
3+
severity: warning
4+
message: >-
5+
"Detected a network listener listening on 0.0.0.0 or an empty string.
6+
This could unexpectedly expose the server publicly as it binds to all
7+
available interfaces. Instead, specify another IP address that is not
8+
0.0.0.0 nor the empty string."
9+
note: >-
10+
[CWE-200] Exposure of Sensitive Information to an Unauthorized Actor
11+
[REFERENCES]
12+
- https://owasp.org/Top10/A01_2021-Broken_Access_Control
13+
14+
rule:
15+
not:
16+
has:
17+
stopBy: end
18+
kind: ERROR
19+
any:
20+
- pattern: tls.Listen($NETWORK, $IP $$$)
21+
- pattern: net.Listen($NETWORK, $IP $$$)
22+
23+
constraints:
24+
IP:
25+
any:
26+
- kind: interpreted_string_literal
27+
regex: ^"0.0.0.0:.*"$|^":.*"$|^'0.0.0.0:.*'$|^':.*'$
28+
- kind: raw_string_literal
29+
regex: ^`0.0.0.0:.*`$|^`:.*`$
30+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
id: avoid-bind-to-all-interfaces-go
2+
snapshots:
3+
? |
4+
l, err := net.Listen("tcp", "0.0.0.0:2000")
5+
: labels:
6+
- source: net.Listen("tcp", "0.0.0.0:2000")
7+
style: primary
8+
start: 10
9+
end: 43
10+
? |
11+
l, err := net.Listen("tcp", ":2000")
12+
: labels:
13+
- source: net.Listen("tcp", ":2000")
14+
style: primary
15+
start: 10
16+
end: 36
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
id: avoid-bind-to-all-interfaces-go
2+
valid:
3+
- |
4+
l, err := net.Listen("tcp", "192.168.1.101:2000")
5+
invalid:
6+
- |
7+
l, err := net.Listen("tcp", "0.0.0.0:2000")
8+
- |
9+
l, err := net.Listen("tcp", ":2000")

0 commit comments

Comments
 (0)