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

tx.param returns wrong value #9

Open
ariopangarih opened this issue Jul 23, 2023 · 1 comment
Open

tx.param returns wrong value #9

ariopangarih opened this issue Jul 23, 2023 · 1 comment

Comments

@ariopangarih
Copy link

Hi! I'm using modsecurity v2.94 version and using your great code.
But i meet problem when i try to make a simple modsec rules.

SecRule REQUEST_URI "@contains dangerous" "id:12345,phase:1,deny,setvar:TX.dangerous=1,status:403,msg:'URL contains dangerous'"

modsec blocks successfully by 403 but page still show 404 Apache (mean Haproxy didn't block the request).

Any help for this issue?

Btw thanks for sharing this code makes me love in networking tech!

@Cpt-Graby
Copy link

Cpt-Graby commented Nov 2, 2023

Hi there,

I personally started working with modsecurity (V2.9.7) and haproxy a week ago, so there may be some errors in my reasoning.

I had the same problem as you with another custom rule. Modsec was logging it as a deny, but the flag in my haproxy stayed at '-101' as if nothing was wrong...
By looking into the origin of the problem, I've been able to trace it back to a logic error.
It occurs in the modsec_wrapper.c code around line 600

	/* Process request headers analysis. */
	status = modsecProcessRequestHeaders(req);
	if (status != DECLINED && status != DONE)
		return_code = status;

	/* Process request body analysis. */
	status = modsecProcessRequestBody(req);
	if (status != DECLINED && status != DONE)
		return_code = status;

	/* End processing. */

	fail = 0;
	if (return_code == -1)
		return_code = 0;

The phase 1 keyword means it handle in the modsecProcessRequestHeaders(req) function but the spoa agent processes (and resets) the status variable with the line status=modsecProcessRequestBody(req) function.
So i guess that's why haproxy reseve a "everthing is fine" info.

So the solution that i thought of were:

  • Put an if statement between the two functions.
  • Change my rule to phase 2, instead of phase 1.

In my case, i choose the second option because i didn't know the design logic in the first place.

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

2 participants