Skip to content

Commit 73990d6

Browse files
committed
fix: skip status_page_exposed warning for Unix socket listeners (#101)
When a server block only listens on Unix sockets, stub_status is inherently inaccessible from the network — no IP restrictions needed.
1 parent b3bb8c4 commit 73990d6

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

gixy/plugins/status_page_exposed.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,36 @@ class status_page_exposed(Plugin):
1515
)
1616
directives = ["stub_status"]
1717

18+
def _server_uses_only_unix_sockets(self, directive):
19+
"""Check if the enclosing server block only listens on Unix sockets.
20+
21+
Args:
22+
directive: The directive to check.
23+
24+
Returns:
25+
True if the server block has at least one listen directive and all
26+
of them use Unix sockets.
27+
"""
28+
for parent in directive.parents:
29+
if parent.name == "server":
30+
listen_directives = parent.find("listen")
31+
if not listen_directives:
32+
return False
33+
return all(
34+
d.args and d.args[0].lower().startswith("unix:")
35+
for d in listen_directives
36+
)
37+
return False
38+
1839
def audit(self, directive):
1940
"""Audit stub_status directive for missing access restrictions.
2041
2142
Args:
2243
directive: The stub_status directive to audit.
2344
"""
45+
if self._server_uses_only_unix_sockets(directive):
46+
return
47+
2448
parent = directive.parent
2549
if not parent:
2650
return
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
server {
2+
listen unix:/run/nginx/status.sock;
3+
4+
location = / {
5+
stub_status;
6+
}
7+
8+
location / {
9+
return 404;
10+
}
11+
}

0 commit comments

Comments
 (0)