fix: null client_connection in Finding 2 eviction path + OOM cleanup fault-injection#7
Draft
Copilot wants to merge 2 commits intocopilot/research-session-handling-vulnerabilitiesfrom
Conversation
… OOM fault-injection test Issue 1: In ngx_http_upstream_get_ntlm_peer, the Finding 2 eviction block was missing `item->client_connection = NULL;` after `item->peer_connection = NULL;`. This violates the ownership invariant documented in the struct comment and is inconsistent with the Finding 1 fix in ngx_http_upstream_free_ntlm_peer. Issue 2: Added NGX_NTLM_TEST_CLEANUP_NULL compile-time fault-injection macro immediately before ngx_http_upstream_free_ntlm_peer. When nginx is built with -DNGX_NTLM_TEST_CLEANUP_NULL, ngx_pool_cleanup_add is overridden to always return NULL, allowing the OOM cleanup handler path to be exercised in tests. Added TEST 6 to t/001-sanity.t documenting the expected behavior when the cleanup handler allocation fails. The test is marked SKIP so it does not run in normal CI; it requires the fault-injection build described in the comment block above the test. Agent-Logs-Url: https://github.com/Securepoint/nginx-ntlm-module/sessions/80daf827-e913-4352-84db-d992d1c15ab0 Co-authored-by: matthias-lay <163420385+matthias-lay@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix missing client connection nullification in eviction path
fix: null client_connection in Finding 2 eviction path + OOM cleanup fault-injection
May 6, 2026
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.
Two follow-up issues identified in PR #6's security fixes for NTLM session hijack prevention.
Changes
ngx_http_upstream_ntlm_module.c— Finding 2 eviction path (ngx_http_upstream_get_ntlm_peer)The stale-credential eviction block was missing
item->client_connection = NULL;, violating the ownership invariant (documented in the struct comment) that every path moving an item out ofconf->cachemust null both connection pointers. Finding 1's fix inngx_http_upstream_free_ntlm_peeralready did this correctly.ngx_http_upstream_ntlm_module.c— Fault-injection macroAdded a compile-time shim to force
ngx_pool_cleanup_addto returnNULL, enabling test coverage of the OOM cleanup handler path (Finding 1) that otherwise has zero automated regression coverage:t/001-sanity.t— TEST 6Documents expected behavior when
ngx_pool_cleanup_addreturnsNULL: the upstream session must not be cached and a follow-up request must not receive the old authenticated session. Marked--- SKIPin normal CI; requires a build with-DNGX_NTLM_TEST_CLEANUP_NULL. A comment block above the test describes the build and run procedure.Original prompt
Context
PR #6 (
fix(security): prevent session hijack via cleanup OOM and stale credential reuse) introduced two security fixes. A code review identified two remaining issues that need to be addressed in a follow-up:Issue 1 — Missing
client_connection = NULLin Finding 2 eviction pathIn
ngx_http_upstream_get_ntlm_peer(Finding 2 fix), when evicting a stale authenticated session due to new credentials,item->client_connectionis not cleared before the item is returned to the free list:This is inconsistent with the Finding 1 fix in
ngx_http_upstream_free_ntlm_peerwhich correctly nulls all three fields:The struct comment (the
in_cacheownership invariant block) documents that every code path moving an item out ofconf->cacheMUST null out both connection pointers. This is violated in the Finding 2 path.Fix: Add
item->client_connection = NULL;immediately afteritem->peer_connection = NULL;in the Finding 2 eviction block insidengx_http_upstream_get_ntlm_peer.Issue 2 — No test coverage for Finding 1 (OOM cleanup handler path)
The Finding 1 fix (OOM in
ngx_pool_cleanup_add) has zero automated test coverage. Add a compile-time fault-injection mechanism and a corresponding test.Fault injection macro
In
ngx_http_upstream_ntlm_module.c, add a compile-time shim so that test builds can forcengx_pool_cleanup_addto returnNULL:Place this immediately before the
ngx_http_upstream_free_ntlm_peerfunction definition (or near the top of the file after the includes), so it only affects that translation unit.New test in
t/001-sanity.tAdd TEST 6 to
t/001-sanity.tthat documents the expected behavior when the cleanup handler cannot be allocated. The test should be marked skip unless the fault-injection build is used, but should clearly document what the test verifies:Also add a brief comment block above TEST 6 explaining how to build nginx with the fault-injection flag for local testing.
Summary of changes required
ngx_http_upstream_ntlm_module.c: Additem->client_connection = NULL;in the Finding 2 eviction block inngx_http_upstream_get_ntlm_peer, and add theNGX_NTLM_TEST_CLEANUP_NULLfault-injection macro block.t/001-sanity.t: Add TEST 6 with the OOM scenario documentation and skip guard.The base branch for this PR is
copilot/research-session-handling-vulnerabilities(the branch from PR #6).The following is the prior conversation context from the user's chat exploration (may be truncated):
User: what do you think about this pr. do you see any problems?
Assistant: Here's my full review of PR #6:
📋 PR Summary
fix(security): prevent session hijack via cleanup OOM and stale credential reuse
ngx_http_upstream_ntlm_module.c,t/001-sanity.t)This PR addresses two distinct security vulnerabilities in the NTLM upstream session cache:
🔧 Core Changes
Finding 1 — Cleanup Handler OOM (
ngx_http_upstream_free_ntlm_peer)Previously, if `ngx_pool_cle...
This pull request was created from Copilot chat.