Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After 3.0.9 is it impossible to include configs by wildcard mask. #2905

Closed
wiseelf opened this issue May 18, 2023 · 10 comments · Fixed by #2909
Closed

After 3.0.9 is it impossible to include configs by wildcard mask. #2905

wiseelf opened this issue May 18, 2023 · 10 comments · Fixed by #2909
Projects

Comments

@wiseelf
Copy link

wiseelf commented May 18, 2023

Describe the bug

After 3.0.9 is it impossible to include configs by wildcard mask. Works well on 3.0.8.

Logs and dumps

2023/05/18 15:12:16 [emerg] 1#1: "modsecurity_rules_file" directive Rules error. File: /etc/nginx/modsec/main.conf. Line: 3. Column: 55. "/usr/local/owasp-modsecurity-crs/rules/*.conf": Not able to open file. Looking at: '"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '/etc/nginx/modsec/"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '/etc/nginx/modsec/"/usr/local/owasp-modsecurity-crs/rules/*.conf"'. in /etc/nginx/nginx.conf:21
nginx: [emerg] "modsecurity_rules_file" directive Rules error. File: /etc/nginx/modsec/main.conf. Line: 3. Column: 55. "/usr/local/owasp-modsecurity-crs/rules/*.conf": Not able to open file. Looking at: '"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '/etc/nginx/modsec/"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '/etc/nginx/modsec/"/usr/local/owasp-modsecurity-crs/rules/*.conf"'. in /etc/nginx/nginx.conf:21

To Reproduce

Just type set this in config
Include "/usr/local/owasp-modsecurity-crs/rules/*.conf"

Expected behavior

All configs are included.

Server (please complete the following information):

  • ModSecurity version ModSecurity v3.0.9
  • WebServer: nginx-1.24.0
  • OS (and distro): nginx docker image

Rule Set (please complete the following information):

@airween
Copy link
Member

airween commented May 18, 2023

2023/05/18 15:12:16 [emerg] 1#1: "modsecurity_rules_file" directive Rules error. File: /etc/nginx/modsec/main.conf. Line: 3. Column: 55. "/usr/local/owasp-modsecurity-crs/rules/*.conf": Not able to open file. Looking at: '"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '/etc/nginx/modsec/"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '/etc/nginx/modsec/"/usr/local/owasp-modsecurity-crs/rules/*.conf"'. in /etc/nginx/nginx.conf:21
nginx: [emerg] "modsecurity_rules_file" directive Rules error. File: /etc/nginx/modsec/main.conf. Line: 3. Column: 55. "/usr/local/owasp-modsecurity-crs/rules/*.conf": Not able to open file. Looking at: '"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '/etc/nginx/modsec/"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '/etc/nginx/modsec/"/usr/local/owasp-modsecurity-crs/rules/*.conf"'. in /etc/nginx/nginx.conf:21

To Reproduce

Just type set this in config Include "/usr/local/owasp-modsecurity-crs/rules/*.conf"

Hmm...

# cat /usr/share/modsecurity-crs/owasp-crs.load 
##
## This file loads OWASP CRS's rules when the package is installed
## It is Included by libapache2-mod-security2
##
Include /etc/modsecurity/crs/crs-setup.conf
Include /etc/modsecurity/crs/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf
Include /usr/share/modsecurity-crs/rules/*.conf
Include /etc/modsecurity/crs/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf
2023/05/18 20:22:27 [notice] 45949#45949: ModSecurity-nginx v1.0.3 (rules loaded inline/local/remote: 0/919/0)
2023/05/18 20:22:28 [notice] 45956#45956: ModSecurity-nginx v1.0.3 (rules loaded inline/local/remote: 0/919/0)

Used with libmodsecurity3 (3.0.9), from here.

Are you sure there is no any apparmor/selinux/unix permission issue?

@wiseelf
Copy link
Author

wiseelf commented May 18, 2023

I'm building from source. Can provide docker file.

var/www/html $ cat /etc/nginx/modsec/main.conf
Include "/etc/nginx/modsec/modsecurity.conf"
Include "/usr/local/owasp-modsecurity-crs/crs-setup.conf"
Include "/usr/local/owasp-modsecurity-crs/rules/*.conf"

/var/www/html $ nginx -t
2023/05/18 19:23:21 [emerg] 9#9: "modsecurity_rules_file" directive Rules error. File: /etc/nginx/modsec/main.conf. Line: 3. Column: 55. "/usr/local/owasp-modsecurity-crs/rules/*.conf": Not able to open file. Looking at: '"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '/etc/nginx/modsec/"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '/etc/nginx/modsec/"/usr/local/owasp-modsecurity-crs/rules/*.conf"'. in /etc/nginx/nginx.conf:23
nginx: [emerg] "modsecurity_rules_file" directive Rules error. File: /etc/nginx/modsec/main.conf. Line: 3. Column: 55. "/usr/local/owasp-modsecurity-crs/rules/*.conf": Not able to open file. Looking at: '"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '/etc/nginx/modsec/"/usr/local/owasp-modsecurity-crs/rules/*.conf"', '/etc/nginx/modsec/"/usr/local/owasp-modsecurity-crs/rules/*.conf"'. in /etc/nginx/nginx.conf:23
nginx: configuration file /etc/nginx/nginx.conf test failed

/var/www/html $ cat /dev//null > /etc/nginx/modsec/main.conf
/var/www/html $ nginx -t
2023/05/18 19:09:18 [notice] 14#14: ModSecurity-nginx v1.0.3 (rules loaded inline/local/remote: 0/0/0)
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Same image with 3.0.8:

/var/www/html $ nginx -t
2023/05/18 19:21:49 [notice] 12#12: ModSecurity-nginx v1.0.3 (rules loaded inline/local/remote: 0/918/0)
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

@wiseelf
Copy link
Author

wiseelf commented May 18, 2023

Here is the POC repo: https://github.com/wiseelf/modsecurity-docker-poc

docker build . -t nginx-modsec:v3.0.8 --build-arg MODSEC_TAG=v3.0.8
docker build . -t nginx-modsec:v3.0.9 --build-arg MODSEC_TAG=v3.0.9

First image works, second fails.

@airween
Copy link
Member

airween commented May 19, 2023

What happens if you remove the " marks?

 Include "/usr/local/owasp-modsecurity-crs/rules/*.conf"

to

 Include /usr/local/owasp-modsecurity-crs/rules/*.conf

@wiseelf
Copy link
Author

wiseelf commented May 19, 2023

Yes, it works without "

/var/www/html $ nginx -t
2023/05/19 07:28:45 [notice] 7#7: ModSecurity-nginx v1.0.3 (rules loaded inline/local/remote: 0/918/0)
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

@airween
Copy link
Member

airween commented May 19, 2023

Yes, it works without "

Thanks. Seems like commit 53cf6eb is broken.

@wiseelf
Copy link
Author

wiseelf commented May 19, 2023

@airween will it be fixed? :)

@airween
Copy link
Member

airween commented May 19, 2023

@airween will it be fixed? :)

I'm sure that will be... once 😃

If I will have some time, I can take a look.

@martinhsv
Copy link
Contributor

@wiseelf , thanks for the report.

@airween, agreed about the commit that broke this use case. I'll create a PR.

@martinhsv martinhsv added this to In progress in v3.0.10 May 29, 2023
@martinhsv martinhsv moved this from In progress to QA in v3.0.10 May 31, 2023
@martinhsv
Copy link
Contributor

This is a an interesting issue because it's not clear that a quoted filepath ought to be treated the same as an unquoted one with respect to special characters. Perhaps the presence of quotes should indicate a more literal interpretation of the filepath, comparable to if one executes ```ls "my*special2.conf" in linux.

I have nevertheless restored the handling to be comparable to pre-v3.0.9. (The change in v3.0.9 was unannounced and presumably unintentional.)

@martinhsv martinhsv moved this from QA to Done in v3.0.10 May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants