fix: null client_connection in Finding 2 eviction path + OOM cleanup fault-injection#7
Draft
Copilot wants to merge 8 commits into
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
Agent-Logs-Url: https://github.com/Securepoint/nginx-ntlm-module/sessions/86d95d3b-5ccd-4dba-a0ca-cad15a41a5e1 Co-authored-by: matthias-lay <163420385+matthias-lay@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Securepoint/nginx-ntlm-module/sessions/86d95d3b-5ccd-4dba-a0ca-cad15a41a5e1 Co-authored-by: matthias-lay <163420385+matthias-lay@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Securepoint/nginx-ntlm-module/sessions/86d95d3b-5ccd-4dba-a0ca-cad15a41a5e1 Co-authored-by: matthias-lay <163420385+matthias-lay@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Securepoint/nginx-ntlm-module/sessions/86d95d3b-5ccd-4dba-a0ca-cad15a41a5e1 Co-authored-by: matthias-lay <163420385+matthias-lay@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Securepoint/nginx-ntlm-module/sessions/86d95d3b-5ccd-4dba-a0ca-cad15a41a5e1 Co-authored-by: matthias-lay <163420385+matthias-lay@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Securepoint/nginx-ntlm-module/sessions/86d95d3b-5ccd-4dba-a0ca-cad15a41a5e1 Co-authored-by: matthias-lay <163420385+matthias-lay@users.noreply.github.com>
Copilot AI
added a commit
that referenced
this pull request
May 7, 2026
- Rewrites ngx_http_upstream_ntlm_module.c with four documented security invariants: I1. Atomic item release via ngx_http_upstream_ntlm_item_release() helper I2. c->read->data (not c->data) for cache item storage on idle connections I3. OOM guard: cleanup-add failure aborts cache insertion (session-hijack fix) I4. Stale-credential eviction on re-auth with established session - Fixes from all open PRs (#3, #6, #7): - Synchronous cleanup handler (no posted events) - Session-hijack via cleanup-OOM (critical) - Stale-credential reuse on established connections (high) - client_connection NULL in eviction path - Fault-injection macro NGX_NTLM_TEST_CLEANUP_NULL for testing - Adds ntlm_time and ntlm_requests directives - Adds notify peer callback pass-through - Updates README.md for v2 with security section - Updates Docker files to nginx 1.28.0 / alpine 3.20 - Adds TEST 5 (stale credential eviction) and TEST 6 (OOM guard, SKIP) to t/001-sanity.t Agent-Logs-Url: https://github.com/Securepoint/nginx-ntlm-module/sessions/3343cf49-d4a7-4188-89b8-5a89fad4a7fe Co-authored-by: matthias-lay <163420385+matthias-lay@users.noreply.github.com>
4 tasks
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.
item->client_connection = NULLin Finding 2 eviction path insidengx_http_upstream_get_ntlm_peer(viangx_http_upstream_ntlm_item_release_to_freehelper, which consistently nulls both connection pointers)NGX_NTLM_TEST_CLEANUP_NULLfault-injection mechanism (implemented asngx_http_upstream_ntlm_pool_cleanup_addwrapper function that returnsNULLwhen the flag is set, replacing the directngx_pool_cleanup_addcall inngx_http_upstream_free_ntlm_peer)t/001-sanity.t— OOM in cleanup handler must not cache the upstream connection (marked--- SKIPfor normal CI; requires a build with-DNGX_NTLM_TEST_CLEANUP_NULL; includes build instructions in a comment block above the test)t/001-sanity.t— new NTLM credentials on an established connection must evict the old sessionOriginal 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.