owasp-modsecurity / owasp-modsecurity/ModSecurity-nginx

Wrong http_code in modsec logs when using auth_request

Open
#363 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Perl
Stars
1.9k
Forks
312
PR merge metrics
No merged PRs in 30d

Description

Problem

When auth_request directive is active, ModSecurity-nginx captures the HTTP status code
from the auth_request subrequest (usually 200 for "pass") instead of the final status
code from the actual backend (proxy_pass).

Setup

location /auth {
	internal;

	modsecurity off;

	proxy_pass http://127.0.0.1:2607/auth?server=$server_name; # => returns 200
	proxy_cache off;
	proxy_pass_request_body	off;

	proxy_set_header X-Forwarded-For $remote_addr;
	proxy_set_header Content-Length "";
	proxy_set_header X-Original-URI $request_uri;

	proxy_intercept_errors	off;
}
auth_request   /auth;
proxy_pass     $upstream; # => returns 404

Scenario

  1. Request comes in: GET /?test=/bin/bash
  2. auth_request /auth → returns 200 (pass)
  3. ModSecurity captures: http_code = 200
  4. proxy_pass $upstream → returns 404
  5. Audit log has: http_code: 200 ❌ (should be 404)

Expected Behavior

ModSecurity should capture the FINAL status code sent to the client, not intermediate
subrequest statuses.

EDIT

The whole response content in the log seems to be the reponse datas of the /auth subrequest, not the proxy request.

nginx version: nginx/1.29.3
ModSecurity-nginx: v1.0.4-2-gfd28e6a

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided nginx configuration with auth_request, proxy_pass, and ModSecurity enabled, then inspect the audit log's http_code and response content for the main request versus the /auth subrequest. Trace how the connector handles subrequest and final response statuses; done means the audit log records the final status and response sent to the client.

Written by the indexing model from the issue text.

Assessment

Tech stack
nginx
Domain
security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.