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

Compiling Ok in AlmaLinux 8.10, but not working #336

Open
decioaalves opened this issue Jan 13, 2025 · 52 comments
Open

Compiling Ok in AlmaLinux 8.10, but not working #336

decioaalves opened this issue Jan 13, 2025 · 52 comments

Comments

@decioaalves
Copy link

decioaalves commented Jan 13, 2025

I managed to compile it ok on AlmaLinux 8.10, a dozen times, in different ways, with 7 different kernels, on three different hardware, and in none of them did I have any problems building the new version of this connector. However, in all of them, the result is broken pages, the server only serves a partial page. In my tests, the result was that when the web page is close to 500Kb, the result is only part of the page, about 70% of the real page.

But compiling the previous version of this connector, it works normally.

Is this problem happening only to me, or has anyone else noticed this problem?

@decioaalves
Copy link
Author

decioaalves commented Jan 13, 2025

In all times, I have recompiled libmodsecurity.so and nginx before compile ngx_http_modsecurity_module, and in all times the result is only head of the pages are supressed. No problems are shown in the logs.

@airween
Copy link
Member

airween commented Jan 13, 2025

Hi @decioaalves,

... and in none of them did I have any problems building the new version of this connector.

Sorry, what is "this" version? Could you explain it exactly?

However, in all of them, the result is broken pages, the server only serves a partial page. In my tests, the result was that when the web page is close to 500Kb, the result is only part of the page, about 70% of the real page.

But compiling the previous version of this connector, it works normally.

Here too: what are the "previous" and "this" versions?

@decioaalves
Copy link
Author

decioaalves commented Jan 13, 2025

Hi @decioaalves,
Sorry, what is "this" version? Could you explain it exactly?

I mean the current version of the 'ModSecurity-nginx' module, as you get when you clone with git. After compile, it generates a 'ngx_http_modsecurity_module.so' library normally, with no warnings.

However, in all of them, the result is broken pages, the server only serves a partial page. In my tests, the result was that when the web page is close to 500Kb, the result is only part of the page, about 70% of the real page.
But compiling the previous version of this connector, it works normally.

Here too: what are the "previous" and "this" versions?

The 'this' version, is the current version. The connector was updated two months ago. The 'previous' version, was a version earlier version, from June, 2024, I was running.

I could to make a debug trace, and I can post it, if you want..

Thank you.

@airween
Copy link
Member

airween commented Jan 14, 2025

The connector was updated two months ago.

You mean about PR #334? That was committed in 2 months ago (19th of Nov, 2024), but was merged few days ago.

To clarify and reproduce this issue we need:

  • commit id of "this" version
  • commit id of "previous" version
  • relevant configs (both Nginx and ModSecurity)
  • a curl example

We need to reproduce the issue.

@decioaalves
Copy link
Author

decioaalves commented Jan 14, 2025

Commit id of 'ModSecurity-nginx' module:

'Older version' (working good version):

git rev-parse HEAD
ef64996
v1.0.3-24-gef64996

'current version' (NOT working good version):

git rev-parse HEAD
fb678c5
v1.0.3-27-gfb678c5

System: AlmaLinux 8.10 (Cerulean Leopard)

Kernels tested:

/boot/kernel-4.18.0-553.34.1.el8_10.x86_64
/boot/kernel-4.18.0-553.33.1.el8_10.x86_64
/boot/kernel-4.18.0-553.32.1.el8_10.x86_64
/boot/kernel-4.18.0-553.30.1.el8_10.x86_64
/boot/kernel-4.18.0-553.27.1.el8_10.x86_64
/boot/kernel-4.18.0-553.el8_10.x86_64

ModSecurity installed pre-requisites

$ sudo dnf -y install pcre pcre-devel libxml2 libxml2-devel curl curl-devel openssl openssl-devel yajl yajl-devel
$ sudo dnf -y install gcc-c++ flex bison GeoIP-devel doxygen zlib-devel
$ sudo dnf -y install lmdb lmdb-devel ssdeep ssdeep-devel lua lua-devel

ModSecurity3 commit id installed in hardware #1:

git rev-parse HEAD
9e685bf86d45b21d1f9f6c4145c3979cc4da0196
v3.0.12-296-g9e685bf

ModSecurity3 commit id installed in machine #2 and #3:

git rev-parse HEAD
41fd21b0fbdbdaf202f830f700027767fbd6fba7
v3.0.12-277-g41fd21b

ModSecurity3 installation

$ sudo git clone --depth 100 -b v3/master --single-branch https://github.com/SpiderLabs/ModSecurity
$ cd ModSecurity
$ sudo git submodule init
$ sudo git submodule update

$ sudo libtoolize && aclocal && autoheader && autoconf && automake --add-missing
The last command is due to 'ltmain.sh no found' error, step recommended from: https://stackoverflow.com/questions/22603163/automake-error-ltmain-sh-not-found
$ sudo sh build.sh
$ sudo ./configure
$ sudo make -j /usr/bin/nproc
$ sudo make install
$ sudo ldconfig

Nginx must be customized, due to the need for compatibility with the CWP WebPanel that is installed
Nginx dependencies checked and installed from "Installing NGINX Dependencies" section from https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#installing-nginx-dependencies
Compilation process based in the tips "CentOS 7 Minimal (dynamic)" sequence steps from https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x :

$ sudo dnf groupinstall 'Development Tools' -y
$ sudo dnf install gcc-c++ flex bison yajl yajl-devel curl-devel curl GeoIP-devel doxygen zlib-devel
$ sudo dnf install lmdb lmdb-devel libxml2 libxml2-devel ssdeep ssdeep-devel lua lua-devel
(changed) $ sudo git clone --depth 100 -b v3/master --single-branch https://github.com/SpiderLabs/ModSecurity
$ cd ModSecurity
$ sudo dnf submodule init
$ sudo dnf submodule update
(due to 'ltmain.sh no found' error, step recommended from: https://stackoverflow.com/questions/22603163/automake-error-ltmain-sh-not-found, added:)
(added) # libtoolize && aclocal && autoheader && autoconf && automake --add-missing
$ sudo ./build.sh
(changed) $ sudo ./configure --prefix=/usr/local/cwpsrv --sbin-path=/usr/local/cwpsrv/bin/cwpsrv --conf-path=/usr/local/cwpsrv/conf/cwpsrv.conf --pid-path=/usr/local/cwpsrv/var/run/nginx.pid --error-log-path=/usr/local/cwpsrv/logs/error_log --http-log-path=/usr/local/cwpsrv/logs/access_log --user=root --group=root --with-http_ssl_module --with-http_gzip_static_module --with-file-aio --with-http_secure_link_module --with-http_ssl_module --add-module=src/misc/ngx_http_auth_pam_module --with-compat --add-dynamic-module=../ModSecurity-nginx
$ sudo make
$ sudo make install
(changed) $ sudo git clone https://github.com/SpiderLabs/ModSecurity-nginx
(changed) $ sudo wget http://nginx.org/download/nginx-1.15.10.tar.gz
(changed) $ sudo tar zxvf nginx-1.15.10.tar.gz
(changed) # cd nginx-1.15.10
(changed) $ sudo ./configure --with-compat --add-dynamic-module=../ModSecurity-nginx
$ sudo make modules
(changed) $ sudo cp objs/ngx_http_modsecurity_module.so /usr/local/cwpsrv/modules
(changed) $ sudo mkdir /usr/local/cwpsrv/conf/security
(changed) $ sudo cp ~/ModSecurity/unicode.mapping /usr/local/cwpsrv/conf/security/

Installed with fresh OWASP CRS 4.3.0, original steps, unchanged
Installation steps based in https://github.com/coreruleset/coreruleset/blob/main/INSTALL.md, just adapted base directoy, instead /etc/crs4/ to /usr/local/cwpsrv/conf/security/crs4/
Added step to install pam-devel to satisfy 'ngx_http_auth_pam_module':

$ sudo dnf install pam-devel

nginx -V

nginx version: nginx/1.15.10
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-22) (GCC)
built with OpenSSL 1.1.1k FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/cwpsrv --sbin-path=/usr/local/cwpsrv/bin/cwpsrv --conf-path=/usr/local/cwpsrv/conf/cwpsrv.conf --pid-path=/usr/local/cwpsrv/var/run/nginx.pid --error-log-path=/usr/local/cwpsrv/logs/error_log --http-log-path=/usr/local/cwpsrv/logs/access_log --user=root --group=root --with-http_ssl_module --with-http_gzip_static_module --with-file-aio --with-http_secure_link_module --with-http_ssl_module --add-module=src/misc/ngx_http_auth_pam_module --with-compat --add-dynamic-module=../ModSecurity-nginx

cwpsrv -V (original binary built from CWP Web Panel, that was tested too, and didn't work):

cwpsrv version: cwpsrv/1.15.10
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017 (running with OpenSSL 1.0.2o-fips 27 Mar 2018)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/cwpsrv --sbin-path=/usr/local/cwpsrv/bin/cwpsrv --conf-path=/usr/local/cwpsrv/conf/cwpsrv.conf --pid-path=/usr/local/cwpsrv/var/run/nginx.pid --error-log-path=/usr/local/cwpsrv/logs/error_log --http-log-path=/usr/local/cwpsrv/logs/access_log --user=root --group=root --with-http_ssl_module --with-http_gzip_static_module --with-file-aio --with-http_secure_link_module --with-http_ssl_module --add-module=src/misc/ngx_http_auth_pam_module

changes to main configuration file from nginx/cwp: /usr/local/cwpsrv/conf/cwpsrv.conf :

worker_processes 2;
+ include /usr/local/cwpsrv/conf/mod-http-modsecurity.conf;
events {
(...)
+ modsecurity on;
+ modsecurity_rules_file /usr/local/cwpsrv/conf/security/conf/modsec_includes.conf;
location / {
(...)

Content from file /usr/local/cwpsrv/conf/mod-http-modsecurity.conf:

load_module modules/ngx_http_modsecurity_module.so;

Original installation from OWASP CRS 4.3.0:
Content from file /usr/local/cwpsrv/conf/security/conf/modsec_includes.conf:

Include /usr/local/cwpsrv/conf/security/crs4/modsecurity.conf (recommended original)
Include /usr/local/cwpsrv/conf/security/crs4/crs-setup.conf
Include /usr/local/cwpsrv/conf/security/crs4/plugins/-config.conf
Include /usr/local/cwpsrv/conf/security/crs4/plugins/
-before.conf
Include /usr/local/cwpsrv/conf/security/crs4/rules/.conf
Include /usr/local/cwpsrv/conf/security/crs4/plugins/
-after.conf

Synthoms:

-ModSecurity-nginx compiling and installing normally in version v1.0.3-27-gfb678c5, no errors nor warnings
-Enabling ModSecurity-nginx version v1.0.3-27-gfb678c5 does not work as expected, almost always gets partial pages, broken pages, rendered with strange characters, like binary characters. The problem with these broken pages is always at the beginning of the pages, about 30% a 40% of the beginning of the pages is suppressed, completely damaging their rendering.
-Disabling ModSecurity in configuration in nginx configuration (just setting "modsecurity off";" and/or commenting both "modsecurity" and "modsecurity_rules_file" diretives), the partial/broken pages error persist.
-Tested with originally built nginx version from CWP (cwpsrv) as dynamic module, but tested too with compiled sources from nginx original sources, version 1.15.10, but continues not working as expected.
-Almost always get partial/broken web pages, from php pages, with ModSecurity-nginx version v1.0.3-27-gfb678c5
-Note: PHP pages are from closed source control webpanel CWP, I have no access to sources.

Solution:

-When disabled ModSecurity-nginx, the pages come back to normal, working as expected (when is removed completely the directive "load_module modules/ngx_http_modsecurity_module.so;" from nginx configuration file /usr/local/cwpsrv/conf/mod-http-modsecurity.conf) unloading it from nginx.
-Another solution was downgrade to ModSecurity-nginx version v1.0.3-24-gef64996

(I'm having trouble making the request with curl, with a password protected page via POST method, as soon as I can, I'll post it here.)

@airween
Copy link
Member

airween commented Jan 15, 2025

Hi @decioaalves,

thanks, I have these ones:

~/src/ModSecurity-nginx$ git describe
v1.0.3-27-gfb678c5
~/src/ModSecurity$ git describe
v3.0.12-296-g9e685bf8

so the newest commits from both repository.

I also installed Nginx, but during some tests yesterday I didn't get any problem. The curl request would be important, what's the request - and if you turn off the module, then please show us the response from the backend. If it contains any sensitive info, please send that to [email protected].

Nginx must be customized, due to the need for compatibility with the CWP WebPanel that is installed

I see, but I need to know the configuration to reproduce the issue. There was a PR (#334) which probably can occur this issue, but without details I can't do anything. Under the mentioned PR you can see some comments, a customer who uses heavily this module confirms that this patch works as well. But of course, we need to find a solution - if we see what's the problem.

@DaveeHorvath
Copy link

Hi,
An issue similar to this one happened for me in a docker container based from debian:bullseye, nginx version 1.18 (installed from apt) using the configuration directly from https://github.com/coreruleset/coreruleset.git with the latest commit of Modsecurity. The requests for a fairly big file (~39kb) fails, as it made the body of the response scrambled as in similar size but a lot of parts moved over one another. The content size matches as well. I would happy to share the request, response and the original file, if that could help? The repo where the issue occured is https://github.com/DaveeHorvath/ascension, and the failing file was main.js. Any other information that would be needed?

@airween
Copy link
Member

airween commented Jan 15, 2025

@DaveeHorvath,

thanks - do you also use the connector with last commit (fb678c5) with Bullseye?

The content size matches as well. I would happy to share the request, response and the original file, if that could help?

Yes, definitely.

The repo where the issue occured is ...

Sorry, I don't use Docker just very rarely, it would be huge help if you could provide the request (with payload) and an example response (that I can set as content).

And many thanks for these!

@decioaalves
Copy link
Author

decioaalves commented Jan 16, 2025

I was unable to create an example using curl, but I was able to generate two *.har files using Chrome, one with the correct page returned, and the other broken.
The sequence shown in these files represents the call to two pages, the first a simple call to the main page of the CWP system. After logging into this page, the following page represents the page in question being analyzed. For simplicity, I will call it the "second page".
The first file, 'request-good.har' represents these two calls working normally, with version v1.0.3-24-gef64996 of ModSecurit-nginx.
The second correct page is returned on line 956 ("text": ...).

So I then upgraded to version v1.0.3-27-gfb678c5, and generated the second file, 'request-broken.har', which shows these same HTTP calls, but results in the second page being broken, being returned at line 954.

Strangely, after doing a scan through the modsecurity audit logs, it shows the second page as if it had been returned to me in its entirety, rather than broken in half. But I had already tested it in two different browsers, Chrome, Firefox and links(text only), and the result is always the same.

request-good.har.zip
request-broken.har.zip

@airween
Copy link
Member

airween commented Jan 16, 2025

@decioaalves,

thanks - I hope this will help me to investigate the issue. Let me check that in next few days.

Cc @Dr-Lazarus-V2 - if you able to check, please help me in this.

@promiteyka
Copy link

promiteyka commented Jan 16, 2025

Have the same problem, this appeared after the commit fb678c5.
tried to work to work with nginx-1.26.2-1.el7.x86_64(EL) and nginx/stable,now 1.26.0-1 amd64(DEB)
Files more than 32kb are cut off at the front and become invalid

@makar112233
Copy link

Hi all. I breaked my brains with debugging same issue.
Please, help with solution.

@DaveeHorvath
Copy link

a temporary solution is to set use an older commit of the connector mentioned by @decioaalves, the link ef64996 should be a working version without this issue.

@airween
Copy link
Member

airween commented Jan 16, 2025

Files more than 32kb are cut off at the front and become invalid

You mean if the response is bigger than 32 kB, then it will be cut off?

@promiteyka
Copy link

Files more than 32kb are cut off at the front and become invalid

You mean if the response is bigger than 32 kB, then it will be cut off?

We came to this through experiments. We have some static on the site, files larger than 32 kb open on the client without the beginning of the file. Although the size is shown the same as on the server.

@airween
Copy link
Member

airween commented Jan 16, 2025

We have some static on the site, files larger than 32 kb

Could you try it with curl? And show the full output (eg use curl -v http://your.site/path/to/static - maybe you should pass --output static.bin)

Now I tried on my environment (with same versions) but everything was fine:

$ curl -v waf.test:8080/outfile.bin --output temp.bin 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Host waf.test:8080 was resolved.
* IPv6: (none)
* IPv4: 127.0.0.1
*   Trying 127.0.0.1:8080...
* Connected to waf.test (127.0.0.1) port 8080
* using HTTP/1.x
> GET /outfile.bin HTTP/1.1
> Host: waf.test:8080
> User-Agent: curl/8.11.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 200 OK
< Server: nginx/1.26.0
< Date: Thu, 16 Jan 2025 13:07:05 GMT
< Content-Type: application/octet-stream
< Last-Modified: Thu, 16 Jan 2025 13:06:26 GMT
< Transfer-Encoding: chunked
< Connection: keep-alive
< ETag: "67890452-19000"
< 
{ [65296 bytes data]
100  100k    0  100k    0     0  1610k      0 --:--:-- --:--:-- --:--:-- 1639k
* Connection #0 to host waf.test left intact

the file:

$ ls -la temp.bin 
-rw-rw-r-- 1 airween airween 102400 Jan 16 14:07 temp.bin

Note that there is no proxy, Nginx serves the files directly.

@promiteyka
Copy link

promiteyka commented Jan 16, 2025

We have some static on the site, files larger than 32 kb

Could you try it with curl? And show the full output (eg use curl -v http://your.site/path/to/static - maybe you should pass --output static.bin)

Now I tried on my environment (with same versions) but everything was fine:

$ curl -v waf.test:8080/outfile.bin --output temp.bin 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Host waf.test:8080 was resolved.
* IPv6: (none)
* IPv4: 127.0.0.1
*   Trying 127.0.0.1:8080...
* Connected to waf.test (127.0.0.1) port 8080
* using HTTP/1.x
> GET /outfile.bin HTTP/1.1
> Host: waf.test:8080
> User-Agent: curl/8.11.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 200 OK
< Server: nginx/1.26.0
< Date: Thu, 16 Jan 2025 13:07:05 GMT
< Content-Type: application/octet-stream
< Last-Modified: Thu, 16 Jan 2025 13:06:26 GMT
< Transfer-Encoding: chunked
< Connection: keep-alive
< ETag: "67890452-19000"
< 
{ [65296 bytes data]
100  100k    0  100k    0     0  1610k      0 --:--:-- --:--:-- --:--:-- 1639k
* Connection #0 to host waf.test left intact

the file:

$ ls -la temp.bin 
-rw-rw-r-- 1 airween airween 102400 Jan 16 14:07 temp.bin

Note that there is no proxy, Nginx serves the files directly.

Yes, I tried both via curl and wget, the result is the same. Can you check the contents of the file? The size is also fine for me when downloading.

This is an example of a downloaded file without mod_sec
Image
And this is the same file but with mod_sec enabled

Image

As you can see, the beginning of the file was cut off and some information was added at the end.

@airween
Copy link
Member

airween commented Jan 16, 2025

Oh, now I see. I tested with a 46kB length JS file, and I got exactly the same result as you (I mean the file is cut off).

Thanks.

@liudongmiao, do you have any idea what would cause this problem? - edit: sorry, this false info.

@airween
Copy link
Member

airween commented Jan 16, 2025

Hi @decioaalves, @DaveeHorvath, @promiteyka and @makar112233,

I can confirm that ef64996 is the last commit where the connector works as we expected.

But I'm afraid the broken commit is 62639fa (part of #326), not fb678c5 .

Could you confirm guys this? It's easy to reproduce: if you check out the broken commit, the file cut effect is still reproducible as with last commit.

@g00g1 ping, it seems like your PR broke the module's normal behavior.

@promiteyka
Copy link

@airween Yes, you are right, the problem is not 62639fa. The last successful build on our CI farm was January 9th, now the last working commit is ef64996

@airween
Copy link
Member

airween commented Jan 17, 2025

To @decioaalves, @DaveeHorvath, @promiteyka and @makar112233:

I think I found the cause of the mentioned problem: in the current code commit @62639fa2 added this line:

            chain->buf->pos = chain->buf->last;

(in line 180).

There is a quick fix but before I merge that I want to review the whole patch again, and I need some help to test that it works as well.

So please if anyone who's able to test this, please help me. A quick help:

git clone --branch issue336fix https://github.com/airween/ModSecurity-nginx.git
cd /path/to/nginx
...configure and make...

Please try the module with this patch with:

@Dr-Lazarus-V2 could you help us in this (run tests)?

@g00g1 could you help me to explain why is that value giving in the mentioned line?

@zero0cool0
Copy link

@airween - Thanks for taking care of this issue.

I've tested the above mentioned issue336fix as part of a custom docker build and it compiles, but any request to a modsec enabled nginx server results in a client-side timeout after a long wait period. I suspect the process is stuck.
Nothing in the logs.
Disabling modsec (i.e. comment out modsecurity on gets everything working again.
Not a lot of help I'm afraid, but wanted to report back.

@airween
Copy link
Member

airween commented Jan 17, 2025

@zero0cool0,

I've tested the above mentioned issue336fix as part of a custom docker build and it compiles, but any request to a modsec enabled nginx server results in a client-side timeout after a long wait period. I suspect the process is stuck. Nothing in the logs. Disabling modsec (i.e. comment out modsecurity on gets everything working again. Not a lot of help I'm afraid, but wanted to report back.

Many thanks for this reply.

It's very interesting, this is what I definitely can't reproduce.

Note, that I don't use Docker (very rarely) - the problem is I don't know how is it possible to debug inside of Docker.

@airween
Copy link
Member

airween commented Jan 17, 2025

@zero0cool0,

I've tested the above mentioned issue336fix as part of a custom docker build and it compiles, but any request to a modsec enabled nginx server results in a client-side timeout after a long wait period.

Could you check with the current master branch and the mentioned "last worked" commit?

@zero0cool0
Copy link

zero0cool0 commented Jan 17, 2025

@airween
I certainly don't intend to make this any weirder, but when I use
https://github.com/owasp-modsecurity/ModSecurity-nginx/archive/refs/heads/master.zip as a source reference to build_module.sh as part of my custom docker build, I run into the issue above.

However, when I clone the master branch via git clone https://github.com/airween/ModSecurity-nginx.git and use this folder as source in build_module.sh I get a well working modsec.

Downloading and unzipping the master.zip file confirms that the content is different to the cloned repo.

Shouldn't the zip archive be the same as the current master?

@airween
Copy link
Member

airween commented Jan 17, 2025

@zero0cool0,

here:

I certainly don't intend to make this any weirder, but when I use
https://github.com/owasp-modsecurity/ModSecurity-nginx/archive/refs/heads/master.zip as a source

you mentioned the repository source as owasp-modsecurity/ModSecurity-nginx. The organization (owner) is the owasp-modsecurity.

But here:

However, when I clone the master branch via git clone https://github.com/airween/ModSecurity-nginx.git and use this folder as source in build_module.sh I get a well working modsec.

you downloaded from my GH repository.

If you take a look at my repository, you can see:

Image

my master branch is behind from the official repository's master.

as part of my custom docker build, I run into the issue above.

You mean the issue that explained in this ticket (namely the downloaded files which bigger than 32 kB cut off)? That's the "expected" now.

Shouldn't the zip archive be the same as the current master?

It must be the same - if you use the same source. Now I downloaded the zip and cloned the git, and got the same content (after I removed the .git directory from the git clone'd directory):

$ diff -rN ModSecurity-nginx-zip ModSecurity-nginx-git
<EMTPY>

Could you try to change to the mentioned branch after you cloned my repository?

git checkout -b issue336fix
git pull origin issue336fix

then run build_module.sh. Then you get the "stacked" Nginx with enabled ModSecurity module?

@zero0cool0
Copy link

Ok, apologies for the confusion I caused.

I've just tested again three things:

  1. Cloning the master from https://github.com/owasp-modsecurity/ModSecurity-nginx results in the issue explained in this ticket (32kB cut off) and renders practically every service I run unusable.

  2. Cloning the master from your GH repo https://github.com/airween/ModSecurity-nginx.git results in a working modsec for me although I'm not able to run all tests.

  3. Finally, with the proposed fix

git checkout -b issue336fix
git pull origin issue336fix

(repo is fast-forwarded)

22:14 $ git status
On branch issue336fix
nothing to commit, working tree clean

... I did some more testing. Not every request results in a timeout.
I can request for example my photo gallery's main URL without any issue. Browser developer tools confirm that content such as various JS files are loaded that are much bigger than 32KB and nothing is cut off. However, as soon as I try to do other things (for example log in), I get the timeout described above. Hard to pinpoint exactly what triggers the timeout.

Similarly with a Nextcloud instance. Some URLs work, a simple curl works as well, some absolutely don't.

By the way, I'm running a modsec disabled nginx instance in parallel with otherwise the same config to rule out other issues.

I'll perform some more tests tomorrow to see if I can pinpoint the issue further if that helps.

@decioaalves
Copy link
Author

decioaalves commented Jan 18, 2025

The 62639fa is broken for me, with *.html, *.json and *.xml above ~32Kb it breaks.

However, with this version 'issue336.fix', I was able to test *.json, *.html files, up to ~64Kb Mb, it worked, and the file is served immediately. I cloned with:

git clone --branch issue336fix https://github.com/airween/ModSecurity-nginx.git

However, for files larger than ~64Kb, the files are not immediately served, and curl gives up after 60 seconds.

The server access log (nothing in the error log) records:

123.213.231.132 - - [17/Jan/2025:23:22:04 -0300] "GET /design/js/libs/teste.json HTTP/1.1" 408 0 "-" "curl/7.61.1"

However, with Chrome navigator, although the 408 (Server Timeout) error is recorded in the server access logs after 60 seconds, seems Chrome request the file, and sometimes the file is served (as recorded in modsec_audit.log file) the first 65535 bytes of the file after more 60 seconds, even though and then, after another 180 seconds, the keep-alive connection is closed in this browser (possibly browser configuration). Sometimes, in the error logs, is recorded only:

2025/01/17 20:27:43 [info] 2361865#0: *27 client 127.0.0.1 closed keepalive connection

@promiteyka
Copy link

To @decioaalves, @DaveeHorvath, @promiteyka and @makar112233:

I think I found the cause of the mentioned problem: in the current code commit @62639fa2 added this line:

        chain->buf->pos = chain->buf->last;

(in line 180).

There is a quick fix but before I merge that I want to review the whole patch again, and I need some help to test that it works as well.

So please if anyone who's able to test this, please help me. A quick help:

git clone --branch issue336fix https://github.com/airween/ModSecurity-nginx.git
cd /path/to/nginx
...configure and make...

Please try the module with this patch with:

@Dr-Lazarus-V2 could you help us in this (run tests)?

@g00g1 could you help me to explain why is that value giving in the mentioned line?

I tried to build with
repo: "https://github.com/airween/ModSecurity-nginx.git"
version: "f4ae9c690ffc9d22957bb7af61b70b4246c30245"
the problem is not reproduced, web-sites open correctly.

@dbc-ca
Copy link

dbc-ca commented Jan 18, 2025

Just for your info, I tried the issue336fix branch and got

wget https://waf-update.*******************.com/lczw.poster.png
--2025-01-18 08:47:38-- https://waf-update.*******************.com/lczw.poster.png
Résolution de waf-update..com (waf-update..com)… 10.10.10.10
Connexion à waf-update..com (waf-update..com)|10.10.10.10|:443… connecté.
requête HTTP transmise, en attente de la réponse… Aucune donnée reçue.
Nouvel essai.

--2025-01-18 08:48:39-- (essai : 2) https://waf-update.*******************.com/lczw.poster.png
Connexion à waf-update..com (waf-update..com)|10.10.10.10|:443… connecté.
requête HTTP transmise, en attente de la réponse… Aucune donnée reçue.
Nouvel essai.

--2025-01-18 08:49:41-- (essai : 3) https://waf-update.*******************.com/lczw.poster.png
Connexion à waf-update..com (waf-update..com)|10.10.10.10|:443… connecté.
requête HTTP transmise, en attente de la réponse… Aucune donnée reçue.
Nouvel essai.

no data coming it seems

@decioaalves
Copy link
Author

I tried to build with repo: "https://github.com/airween/ModSecurity-nginx.git" version: "f4ae9c690ffc9d22957bb7af61b70b4246c30245" the problem is not reproduced, web-sites open correctly.

Yes, I tryed too at this moment, and I can confirm, this version it's funcional and working.

@aspirantzhang
Copy link

aspirantzhang commented Jan 19, 2025

For the past two weeks, I’ve been deploying a new nginx+modsecurity setup every day. However, strangely, this week it suddenly stopped working without any error logs. I thought I was just being careless and started doubting myself, which really got me down… Until today, I found this post.

Based on the timing, I believe the issue could be related to the merge fb678c5.

I tested a WordPress site by cloning the repository with the following command:

git clone --branch issue336fix https://github.com/airween/ModSecurity-nginx.git

This commit seemed to make some improvements, but it still didn’t work as expected.

However, reverting to commit ef64996 seems to fully resolve the issue.

@dbc-ca
Copy link

dbc-ca commented Jan 19, 2025

Hi! I retried the patch

git clone --branch issue336fix https://github.com/airween/ModSecurity-nginx.git

because I saw in the comment that for some people it was working. But for me, it previously dit not work,
here is what I found, at least on my waf.

on the waf I created 2 files

dd if=/dev/zero bs=1 count=65536 2>/dev/null | tr '\0' 'A' > 65536bytes.txt
dd if=/dev/zero bs=1 count=65537 2>/dev/null | tr '\0' 'A' > 65537bytes.txt

on client : curl -v https://waf-update.DEBUG.com/65536bytes.txt
The 16kb file went ok ( md5sum matched ) although I got

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA* Connection #0 to host waf-update.DEBUG.com left intact
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

It did download correctly.

the 16kb + 1 byte file did not

  • Host waf-update.DEBUG.com:443 was resolved.

  • IPv6: (none)

  • IPv4: ###.###.###.###

  • Trying ###.###.###.###:443...

  • Connected to waf-update.DEBUG.com (###.###.###.###) port 443

  • ALPN: curl offers h2,http/1.1

  • (304) (OUT), TLS handshake, Client hello (1):

  • CAfile: /etc/ssl/cert.pem

  • CApath: none

  • (304) (IN), TLS handshake, Server hello (2):

  • (304) (OUT), TLS handshake, Client hello (1):

  • (304) (IN), TLS handshake, Server hello (2):

  • (304) (IN), TLS handshake, Unknown (8):

  • (304) (IN), TLS handshake, Certificate (11):

  • (304) (IN), TLS handshake, CERT verify (15):

  • (304) (IN), TLS handshake, Finished (20):

  • (304) (OUT), TLS handshake, Finished (20):

  • SSL connection using TLSv1.3 / AEAD-AES256-GCM-SHA384 / [blank] / UNDEF

  • ALPN: server accepted http/1.1

  • Server certificate:

  • subject: CN=waf-update.DEBUG.com

  • start date: Jan 17 15:15:11 2025 GMT

  • expire date: Apr 17 15:15:10 2025 GMT

  • subjectAltName: host "waf-update.DEBUG.com" matched cert's "waf-update.DEBUG.com"

  • issuer: C=US; O=Let's Encrypt; CN=E5

  • SSL certificate verify ok.

  • using HTTP/1.x
    GET /65537bytes.txt HTTP/1.1
    Host: waf-update.DEBUG.com
    User-Agent: curl/8.7.1
    Accept: /

  • Request completely sent off

  • Empty reply from server

  • Closing connection
    curl: (52) Empty reply from server

@dbc-ca
Copy link

dbc-ca commented Jan 19, 2025

With the main branch ( one that does not work ) https://github.com/owasp-modsecurity/ModSecurity-nginx
Here is other thing I found..

On the WAF, I created a file

htdocs# cat gen.sh
#!/bin/bash
letters=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)

for i in "${!letters[@]}"; do
printf "%0.s${letters[i]}" $(seq 1 8192) >> abc.txt
done

it is a sequence of 8kb of AAA BBB CCC ... ZZZ

md5sum abc.txt
439f6849755c4605653131c836e7d4ed abc.txt

-------- NOW ON CLIENT SIDE -------
% curl -o abc.txt https://waf-update.DEBUG.com/abc.txt
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 208k 0 208k 0 0 2476k 0 --:--:-- --:--:-- --:--:-- 2506k

% % md5 abc.txt
MD5 (abc.txt) = dc3b81fdc1fb60eacbe0a86b4f857141

since the file is only letter it can be edited without messing the terminal, so when I cat the file abc.txt into the terminal
it only contains YYY...ZZZZ..WWWWW....XXXX...YYYY..ZZZZZ....WWW..XXX

but the file sizes match

@airween
Copy link
Member

airween commented Jan 19, 2025

Ok, apologies for the confusion I caused.

No worries :)

1. Cloning the master from `https://github.com/owasp-modsecurity/ModSecurity-nginx` results in the issue explained in this ticket (32kB cut off) and renders practically every service I run unusable.

yep,

2. Cloning the master from your GH repo `https://github.com/airween/ModSecurity-nginx.git` results in a working modsec for me although I'm not able to run all tests.

yes, that's the "old" version, probably without this bug.

3. Finally, with the proposed fix
git checkout -b issue336fix
git pull origin issue336fix

(repo is fast-forwarded)

22:14 $ git status
On branch issue336fix
nothing to commit, working tree clean

... I did some more testing. Not every request results in a timeout. I can request for example my photo gallery's main URL without any issue. Browser developer tools confirm that content such as various JS files are loaded that are much bigger than 32KB and nothing is cut off. However, as soon as I try to do other things (for example log in), I get the timeout described above. Hard to pinpoint exactly what triggers the timeout.

Similarly with a Nextcloud instance. Some URLs work, a simple curl works as well, some absolutely don't.

yes, I think it depends on CT (Content-Type), see ModSecurity's config.

If you could check the types, that would be help.

By the way, I'm running a modsec disabled nginx instance in parallel with otherwise the same config to rule out other issues.

yes, that's the normal behavior.

I'll perform some more tests tomorrow to see if I can pinpoint the issue further if that helps.

Thanks!

@airween
Copy link
Member

airween commented Jan 19, 2025

For the past two weeks, I’ve been deploying a new nginx+modsecurity setup every day. However, strangely, this week it suddenly stopped working without any error logs. I thought I was just being careless and started doubting myself, which really got me down… Until today, I found this post.

Based on the timing, I believe the issue could be related to the merge fb678c5.

Hmm, that's very interesting.

I tested a WordPress site by cloning the repository with the following command:

git clone --branch issue336fix https://github.com/airween/ModSecurity-nginx.git

This commit seemed to make some improvements, but it still didn’t work as expected.

However, reverting to commit ef64996 seems to fully resolve the issue.

What happens if you revert only the last commit and / or check out to 62639fa? If it works that confirms the wrong patch is the last one. If not, then probably we should check the last two commits. (Based on your sentence above: I’ve been deploying a new nginx+modsecurity setup every day. However, strangely, this week it suddenly stopped working without any error logs - I mean you mentioned this week, and I merged only the last commit this week. If you haven't faced this issue before, then it means the last commit is wrong.)

@airween
Copy link
Member

airween commented Jan 19, 2025

The 62639fa is broken for me, with *.html, *.json and *.xml above ~32Kb it breaks.

However, with this version 'issue336.fix', I was able to test *.json, *.html files, up to ~64Kb Mb, it worked, and the file is served immediately.

What about other types?

What does mean "up to ~64Kb Mb" - have you checked with MB content?

@airween
Copy link
Member

airween commented Jan 19, 2025

I tried to build with repo: "https://github.com/airween/ModSecurity-nginx.git" version: "f4ae9c690ffc9d22957bb7af61b70b4246c30245" the problem is not reproduced, web-sites open correctly.

Thanks.

What kind of file types have you checked? I mean json, html, ...? And with which sizes?

@airween
Copy link
Member

airween commented Jan 19, 2025

Just for your info, I tried the issue336fix branch and got

wget https://waf-update.*******************.com/lczw.poster.png --2025-01-18 08:47:38-- https://waf-update.*******************.com/lczw.poster.png Résolution de waf-update..com (waf-update..com)… 10.10.10.10 Connexion à waf-update..com (waf-update..com)|10.10.10.10|:443… connecté. requête HTTP transmise, en attente de la réponse… Aucune donnée reçue. Nouvel essai.

--2025-01-18 08:48:39-- (essai : 2) https://waf-update.*******************.com/lczw.poster.png Connexion à waf-update..com (waf-update..com)|10.10.10.10|:443… connecté. requête HTTP transmise, en attente de la réponse… Aucune donnée reçue. Nouvel essai.

--2025-01-18 08:49:41-- (essai : 3) https://waf-update.*******************.com/lczw.poster.png Connexion à waf-update..com (waf-update..com)|10.10.10.10|:443… connecté. requête HTTP transmise, en attente de la réponse… Aucune donnée reçue. Nouvel essai.

no data coming it seems

Thanks - I can confirm, for eg. png files are timed out. But json files can be downloaded, for eg.

@airween
Copy link
Member

airween commented Jan 19, 2025

Yes, I tryed too at this moment, and I can confirm, this version it's funcional and working.

Unfortunately just partially working. We should figure out which files and sizes are timed out.

@decioaalves
Copy link
Author

The 62639fa is broken for me, with *.html, *.json and *.xml above ~32Kb it breaks.
However, with this version 'issue336.fix', I was able to test *.json, *.html files, up to ~64Kb Mb, it worked, and the file is served immediately.

What about other types?

What does mean "up to ~64Kb Mb" - have you checked with MB content?

Sorry, was a typo.
I mean 64Kb, that is 65536 bytes.
The types I tried was .html, .xml, .json and .js files.

When I did cloned with:

git clone https://github.com/airween/ModSecurity-nginx.git

... and the sizes reached up to 512Mb, and everything was ok.

Yes, I tryed too at this moment, and I can confirm, this version it's funcional and working.

Unfortunately just partially working. We should figure out which files and sizes are timed out.

Ok, since you didn't announce it, I actually thought that it would still be a work in progress.

@aspirantzhang
Copy link

For the past two weeks, I’ve been deploying a new nginx+modsecurity setup every day. However, strangely, this week it suddenly stopped working without any error logs. I thought I was just being careless and started doubting myself, which really got me down… Until today, I found this post.
Based on the timing, I believe the issue could be related to the merge fb678c5.

Hmm, that's very interesting.

I tested a WordPress site by cloning the repository with the following command:

git clone --branch issue336fix https://github.com/airween/ModSecurity-nginx.git

This commit seemed to make some improvements, but it still didn’t work as expected.
However, reverting to commit ef64996 seems to fully resolve the issue.

What happens if you revert only the last commit and / or check out to 62639fa? If it works that confirms the wrong patch is the last one. If not, then probably we should check the last two commits. (Based on your sentence above: I’ve been deploying a new nginx+modsecurity setup every day. However, strangely, this week it suddenly stopped working without any error logs - I mean you mentioned this week, and I merged only the last commit this week. If you haven't faced this issue before, then it means the last commit is wrong.)

AlmaLinux 9.5 + nginx-1.26.2

fb678c5 -> Failed
ae30826 -> Failed
62639fa -> Failed
ef64996 -> Success!
2e4cbf7-> Success!

However, I am quite certain that around January 3rd, I deployed the latest version of ModSecurity-nginx without encountering any issues. Based on the timeline, it should have been the version ae30826.

@NoipName
Copy link

Hello everyone,

I have the issue when i tried to deploy last week, before that i didn't have the issue.

I tried the path ef64996 and 2e4cbf7 and that not work for me

i did:
git clone https://github.com/owasp-modsecurity/ModSecurity-nginx
cd /opt/ModSecurity/ModSecurity-nginx
git checkout 62639fa

i did right ?

========================

After that, i tried to use another "ngx_http_modsecurity_module.so" module from one of my server where is working

i'm on the last commit of the main branch and my module date is October

Image

I dont know how work ModSecurity and what is a different between working module and the new module but it's work for me

@airween
Copy link
Member

airween commented Jan 20, 2025

62639fa -> Failed

Hmm... this is interesting. Could you show me details about how did you check? I mean file (typ), size, used settings, rule set, etc...

Now I tried this commit and it worked for me.

However, I am quite certain that around January 3rd, I deployed the latest version of ModSecurity-nginx without encountering any issues. Based on the timeline, it should have been the version ae30826.

Thanks, I'll check that too.

@aspirantzhang
Copy link

aspirantzhang commented Jan 21, 2025

62639fa -> Failed

Hmm... this is interesting. Could you show me details about how did you check? I mean file (typ), size, used settings, rule set, etc...

Now I tried this commit and it worked for me.

However, I am quite certain that around January 3rd, I deployed the latest version of ModSecurity-nginx without encountering any issues. Based on the timeline, it should have been the version ae30826.

Thanks, I'll check that too.

To facilitate better testing, I’ve set up a temporary virtual server (located in Virginia, USA) and sent you the login details via email ([email protected], 'ModSecurity-nginx Debug Server – ISSUE336'). Feel free to modify and debug as needed.

Server Details

  • A fresh WordPress installation
  • Running Nginx 1.26.2 + PHP 8.3 + MariaDB 11.6
  • ModSecurity is configured with the Core Rule Set without any custom rules

Website Information

  • Website URL: http://aaa.aspirantzhang.com
  • Website root: /home/wwwroot/aaa.com/public/
  • Nginx vhost config: /usr/local/nginx/conf/vhosts/aaa.com.conf
  • Nginx main config: /usr/local/nginx/conf/nginx.conf
  • PHP-FPM config: /usr/local/php/etc/php-fpm.d/aaa.conf
  • ModSecurity-nginx module: /usr/local/ModSecurity-nginx

Currently, the site is running commit fb678c5, and the issue is visible as soon as the site is accessed. Refreshing the page results in different outputs each time.

ModSecurity Configuration in Nginx

modsecurity on;
modsecurity_rules_file /etc/nginx/modsec/main.conf;

Further Testing

To test with a different commit, simply switch the commit and recompile Nginx (a script is available, and the process takes about 3 minutes):

cd /usr/local/ModSecurity-nginx
git checkout ef64996
~/install-nginx.sh

I'm not sure how to create a more comprehensive test case. If possible, please take a look directly on the server. I’d really appreciate it!

@kejilion
Copy link

Since I don't understand the code, I can't give more help.
I want to know if the problem has been solved?
Or is it in the process of being solved?
When is the expected fix for this problem?
Thank you for your contribution, I hope modsecurity will be better, I like this project very much.

@airween
Copy link
Member

airween commented Jan 24, 2025

I want to know if the problem has been solved? Or is it in the process of being solved?

Not yet, it's under investigation.

When is the expected fix for this problem?

I don't know. A workaround is expected on next week at least.

Thank you for your contribution, I hope modsecurity will be better, I like this project very much.

Thank you.

@airween
Copy link
Member

airween commented Jan 24, 2025

Here are some news around this issue: I wasn't able to work on this in last few days, but before that I tried to explore what's the root cause. Unfortunately I couldn't find that. I try it again in next few days, but if I can finish that, I can solve this issue this way:

If anyone has an opinion/better idea, please let me know.

@SonNgo2211
Copy link

SonNgo2211 commented Jan 27, 2025

Oh, I recently rebuilt modsecurity with nginx 1.27.3, and it seems there was some change in the modsec source code that caused me to have the same problem. My js files have also been truncated, losing their leading parts. Only when I configured proxy_buffer_size to be 128k and proxy_buffers to be 8 16m was this problem resolved, my js files were loaded normally.

@SonNgo2211
Copy link

In addition, I am also having a problem with my website failing to decode the website content:
Image

Another of my websites using websocket had the following error. I used modsecurity off on that path to stop this problem:
Image

I think it's related to this issue so I'll provide more information here in the hope of being of assistance.

@airween
Copy link
Member

airween commented Jan 28, 2025

Hi @SonNgo2211,

Oh, I recently rebuilt modsecurity with nginx 1.27.3, and it seems there was some change in the modsec source code that caused me to have the same problem. My js files have also been truncated, losing their leading parts. Only when I configured proxy_buffer_size to be 128k and proxy_buffers to be 8 16m was this problem resolved, my js files were loaded normally.

thanks for the suggested workarounds.

@ne20002
Copy link

ne20002 commented Jan 28, 2025

I ran into this today with the latest nginx version from docker hub.

I worked around by going back to the version 4.10-nginx-202501050801. Having this problem existing in a version published on docker hub is unfortunate.

Originally posted by @ne20002 in #3333

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests