Repository navigation
fix(dedup): exempt verified Undertow session expiry from XNIO latch - #200
Merged
Merged
Conversation
Undertow's InMemorySessionManager$SessionImpl schedules a timer
cancelTask ($2#run) that executes outside any HTTP request window and
dispatches a SessionImpl$2$1 task onto SessionImpl.this.worker via
XnioWorker.execute(Runnable). Because RequestGate.handXnioWorker had
no verification for this internal expiry dispatch, every Undertow
session expiry latched asyncExecutors=false
(untracked-async:xnio-worker-outside-window), even with no application
session listeners.
Verify Undertow's session-expiry dispatch by construction without any
blanket allowlist:
- ServerEntries.wrapXnioWorkerExecute passes both the receiver (this)
and task to RequestGate.handXnioWorker(Object, Runnable), keeping
the 1-arg overload for compatibility (receiver=null fails closed).
- SinkAllowlist.isAllowedUndertowSessionExpiryXnioDispatch checks:
1. exact runtime task class InMemorySessionManager$SessionImpl$2$1;
2. exact immediate external caller frame (skipping only Keploy and
org.xnio.XnioWorker, never reflection or app frames)
InMemorySessionManager$SessionImpl$2#run;
3. same-ClassLoader owner-identity chain: task.this$1 is exact
SessionImpl$2, cancelTask.this$0 is exact SessionImpl,
session.cancelTask == cancelTask, and session.worker == receiver.
- RequestGate wraps verified expiry tasks in a non-Hand
XnioIdleBackgroundTask recognized by enterXnioWorkerDispatch so
XnioWorker's internal pool/thread sinks stay clean while the task
runs on the worker thread with no window permit and no tracked
dispatch scope (application listeners and user async work still fail
closed).
- Drop the Undertow exclusions from SessionListenerHookTest now that
listener-free Undertow expiry keeps asyncExecutors=true while
application listeners and HttpSessionBindingListener still
contaminate and latch.
Signed-off-by: slayerjain <shubhamkjain@outlook.com>
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.
Root Cause
Undertow's
InMemorySessionManager$SessionImplschedules a timercancelTask(SessionImpl$2#run) on the XNIO I/O thread outside any HTTP request window. When the timer fires,SessionImpl$2#run()dispatchesnew SessionImpl$2$1(this)ontoSessionImpl.this.workerviaorg.xnio.XnioWorker.execute(Runnable).Because
RequestGate.handXnioWorkertreated every outside-windowXnioWorker.executecall as an untracked background worker, every Undertow session expiry permanently latchedasyncExecutors=false(untracked-async:xnio-worker-outside-window), even on listener-free apps (both standalone Undertow 2.2/2.3 and Spring Boot 3.3spring-boot-starter-undertow).Fix (By Construction, No Blanket Allowlist)
ServerEntries.wrapXnioWorkerExecute: passes boththis(ALOAD 0) andtask(ALOAD 1) toRequestGate.handXnioWorker(Object, Runnable). The 1-arghandXnioWorker(Runnable)overload is retained for binary/source compatibility and delegates withreceiver = null(fail-closed).SinkAllowlist.isAllowedUndertowSessionExpiryXnioDispatch: verifies Undertow's internal expiry dispatch end-to-end before permitting it:receiver != nullandtask != null;io.undertow.server.session.InMemorySessionManager$SessionImpl$2$1(O(1) fail-closed for all other tasks without walking the stack);org.xnio.XnioWorker, never reflection/MethodHandles or app frames) equalsio.undertow.server.session.InMemorySessionManager$SessionImpl$2#run;ClassLoaderowner-identity chain:task.this$1is exactInMemorySessionManager$SessionImpl$2,cancelTask.this$0is exactInMemorySessionManager$SessionImpl,session.cancelTask == cancelTask, andsession.worker == receiver.RequestGate: wraps verified expiry dispatches in a non-HandXnioIdleBackgroundTaskrecognized byenterXnioWorkerDispatchsoXnioWorker's internal task-pool/thread-start sinks stay clean during the dispatch whileSessionImpl$2$1#run()executes on the worker thread with no window permit and no tracked-dispatch scope. Application session listeners (hooked by fix(dedup): contaminate and latch asyncExecutors on background HTTP session-expiry listeners #198) and application async work submitted toXnioWorker.executeoutside a request window still fail closed and latchasyncExecutors=false.SessionListenerHookTest: re-enables all 4 Undertow assertions previously skipped because of this pre-existing XNIO latch (baseline warm,HttpSessionBindingListener.valueUnbound, synchronous in-requestinvalidate(), and listener-free background expiry).Verification
ws=false,ws=true) + Spring Boot 3.3.5starter-undertow(bothKEPLOY_PROVENunset andKEPLOY_PROVEN=1):main(fc11dd7): reproduces failure across all 6 rows (asyncExecutors=false,untracked-async:xnio-worker-outside-window).base_async=true, post-expiryasyncExecutors=true,contaminated=[], zero latches).JdkSinkBridgeTest#undertowSessionExpiryXnioDispatchAllowsOnlyExactOwnedCancelTaskAndFailsClosedOtherwise: covers real Undertow 2.2SessionImpl$2#runarmed/unarmed positive paths and adversarial negative matrix (direct/reflectiveSessionImpl$2$1, arbitrary appRunnable, null receiver, foreignXnioWorker, wrong caller, detachedSessionImpl$2, forged same-ClassLoaderRunnablewith matchingthis$1).ForkedAsyncAndHonestyTest: verifies Undertow 2.2.37 and Undertow 2.3.18 session expiry alongside outside-window appXnioWorker.executeescape detection in both prefix and index modes (KEPLOY_PROVENunset andKEPLOY_PROVEN=1).SessionListenerHookTest(with all 4 Undertow exclusions dropped): 6/6 pass in bothKEPLOY_PROVENunset andKEPLOY_PROVEN=1.keploy-sdktest suite,./scripts/smoke-javaagent.sh, and reproducible release build (mvn -B -P release -Dgpg.skip -DskipTests clean verify+ no-cleanverify+sha256sum -c) all pass.SinkAllowlistexemption, caller check, task-class check, worker identity,cancelTaskidentity,enterXnioWorkerDispatch, andServerEntriesreceiver passing) all fail the unit suite cleanly (7/7 killed).