fix: free intervention.url on redirect path and check ngx_list_push r…#378
Open
eilandert wants to merge 1 commit into
Open
fix: free intervention.url on redirect path and check ngx_list_push r…#378eilandert wants to merge 1 commit into
eilandert wants to merge 1 commit into
Conversation
…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
|
Member
|
thanks for the PR - do you think it would be possible to add some tests to check this feature? |
There was a problem hiding this comment.
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 returningNGX_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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



…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: