nginx check regex in location field

This commit is contained in:
Kay0u 2023-12-29 00:48:47 +01:00
parent c989679ba3
commit 5baae31c1f
No known key found for this signature in database
GPG key ID: AE1DCADB6415A156

View file

@ -1422,6 +1422,27 @@ class Configurations(TestSuite):
'more_set_headers "Header-Name: value"' 'more_set_headers "Header-Name: value"'
) )
@test()
def misc_nginx_check_regex_in_location(self):
app = self.app
for filename in (
os.listdir(app.path + "/conf") if os.path.exists(app.path + "/conf") else []
):
# Ignore subdirs or filename not containing nginx in the name
if (
not os.path.isfile(app.path + "/conf/" + filename)
or "nginx" not in filename
):
continue
cmd = 'grep -q -IhEro "location ~ __PATH__\" %s' % filename
if os.system(cmd) != 0:
yield Warning(
"When using regexp in the nignx location field (location ~ __PATH__), start the path with ^ (location ~ ^__PATH__)."
)
@test() @test()
def misc_nginx_path_traversal(self): def misc_nginx_path_traversal(self):