Merge pull request #131 from Salamandar/fix_nginx_regex

Fix nginx regex
This commit is contained in:
Tagada 2024-02-20 17:15:09 +01:00 committed by GitHub
commit 61213c1bb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1432,6 +1432,27 @@ class Configurations(TestSuite):
f"\nOffending line(s) [{lines}]" f"\nOffending line(s) [{lines}]"
) )
@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' % (app.path + "/conf/" + filename)
if os.system(cmd) != 0:
yield Warning(
"When using regexp in the nginx location field (location ~ __PATH__), start the path with ^ (location ~ ^__PATH__)."
)
@test() @test()
def misc_nginx_path_traversal(self): def misc_nginx_path_traversal(self):