Skip to content

fix: free intervention.url on redirect path and check ngx_list_push r…#378

Open
eilandert wants to merge 1 commit into
owasp-modsecurity:masterfrom
eilandert:fix/intervention-url-memory-leak
Open

fix: free intervention.url on redirect path and check ngx_list_push r…#378
eilandert wants to merge 1 commit into
owasp-modsecurity:masterfrom
eilandert:fix/intervention-url-memory-leak

Conversation

@eilandert
Copy link
Copy Markdown

…eturn

When ModSecurity fires a redirect intervention, intervention.url is allocated by msc_intervention() and must be freed by the caller. Previously it was leaked on every redirect, causing unbounded memory growth on busy servers using redirect-based rules.

Additionally, the ngx_list_push() call was not checked for NULL before dereferencing the returned pointer, which would cause a worker crash under out-of-memory conditions.

Fixes:

  • Add free(intervention.url) before returning the redirect status code
  • Add NULL check for ngx_list_push() return; free url and return 500 on allocation failure

…eturn

When ModSecurity fires a redirect intervention, intervention.url is
allocated by msc_intervention() and must be freed by the caller.
Previously it was leaked on every redirect, causing unbounded memory
growth on busy servers using redirect-based rules.

Additionally, the ngx_list_push() call was not checked for NULL before
dereferencing the returned pointer, which would cause a worker crash
under out-of-memory conditions.

Fixes:
- Add free(intervention.url) before returning the redirect status code
- Add NULL check for ngx_list_push() return; free url and return 500
  on allocation failure

Severity: Critical (memory leak) / Medium (NULL deref)
Reported-by: Security audit 2026-05-13
@sonarqubecloud
Copy link
Copy Markdown

@airween
Copy link
Copy Markdown
Member

airween commented May 14, 2026

@eilandert,

thanks for the PR - do you think it would be possible to add some tests to check this feature?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses two issues in ngx_http_modsecurity_process_intervention: a memory leak of intervention.url on the redirect path, and a missing NULL check on the ngx_list_push() return value that could cause a worker crash under OOM.

Changes:

  • Add free(intervention.url) before returning on the redirect path.
  • Add a NULL check after ngx_list_push() and free the URL before returning NGX_HTTP_INTERNAL_SERVER_ERROR.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +224 to +225
free(intervention.url);
intervention.url = NULL;
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

Successfully merging this pull request may close these issues.

3 participants