From 377f425d174b2e77ada0ff51d1af4a5e05af3bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Tue, 20 Feb 2024 16:44:35 +0100 Subject: [PATCH 1/3] Reapply "nginx check regex in location field" This reverts commit 8fb78d904b6df4566191623487c3e32e134745b0. Original commit from Kayou --- package_linter.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/package_linter.py b/package_linter.py index 51f5a22..0065751 100755 --- a/package_linter.py +++ b/package_linter.py @@ -1432,6 +1432,27 @@ class Configurations(TestSuite): 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' % 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() def misc_nginx_path_traversal(self): From 107e6ed790c6c2a56c0b15a1d0b163c183b9f67e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Tue, 20 Feb 2024 16:47:16 +0100 Subject: [PATCH 2/3] Fix test misc_nginx_check_regex_in_location : /conf/ was missing... --- package_linter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package_linter.py b/package_linter.py index 0065751..e962f75 100755 --- a/package_linter.py +++ b/package_linter.py @@ -1445,7 +1445,7 @@ class Configurations(TestSuite): ): continue - cmd = 'grep -q -IhEro "location ~ __PATH__" %s' % filename + cmd = 'grep -q -IhEro "location ~ __PATH__" %s' % (app.path + "/conf/" + filename) if os.system(cmd) != 0: yield Warning( From 25603267c67044b7500a4f1df293a24a7370d240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Tue, 20 Feb 2024 17:14:20 +0100 Subject: [PATCH 3/3] Fix typo nginx --- package_linter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package_linter.py b/package_linter.py index e962f75..761a092 100755 --- a/package_linter.py +++ b/package_linter.py @@ -1449,7 +1449,7 @@ class Configurations(TestSuite): if os.system(cmd) != 0: yield Warning( - "When using regexp in the nignx location field (location ~ __PATH__), start the path with ^ (location ~ ^__PATH__)." + "When using regexp in the nginx location field (location ~ __PATH__), start the path with ^ (location ~ ^__PATH__)." )