You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
↑ Replaces wildcard session listening with per-session 127.0.0.1 sockets, constant-time 256-bit JavaDebug-Auth verification under an absolute deadline, isolated listener/handshake/session worker pools, immediate listener closure after one authenticated client, and a 30s unused-session reaper. ↑ Enforces initialize lifecycle gating prior to argument deserialization, byte-accurate UTF-8 Content-Length framing, and loopback-only JDI launch listening with bounded JDWP-Handshake and packet sizes. ↓ Paired protocolVersion: 2 session negotiation requires companion client PR microsoft/vscode-java-debug#1736 when bundling the updated server plugin JAR.
Diagnosis confidence
10/10
↑ Directly traced wildcard ServerSocket(0) binding in JavaDebugServer and JDI SocketListeningConnector, missing pre-initialize command gating in DebugAdapter, and String UTF-16 character slicing in AbstractProtocolServer.
Evidence fit
10/10
↑ Verified with Checkstyle, 63 core JUnit tests + 33 Eclipse/OSGi JDT plugin tests (./mvnw -B clean verify), and live end-to-end .vsix verification in VS Code across launch, noDebug, and attach workflows.
Summary
Companion server changes for microsoft/vscode-java-debug#1736. Hardens Debug Adapter Protocol (DAP) session transport, initialize lifecycle enforcement, UTF-8 message framing, and JDI launch socket binding.
Changes
Per-session loopback DAP server & handshake authentication
Allocates a dedicated 127.0.0.1ServerSocket per vscode.java.startDebugSession (protocolVersion >= 2), verifies a 256-bit SecureRandomJavaDebug-Auth header via MessageDigest.isEqual within an absolute handshake deadline, closes the listener once a single valid client authenticates, expires unclaimed sessions after 30 seconds, isolates listener/handshake/session worker pools with per-listener candidate bounds, and rejects unversioned 0-arg startDebugSession calls by default.
Frames Content-Length headers and JSON payloads over raw UTF-8 byte counts instead of String UTF-16 code units, with bounded header (8 KiB) and payload (32 MiB) limits.
Binds JDI launch listeners strictly to 127.0.0.1, performs debugger-first JDWP-Handshake verification under an absolute deadline, caps incoming JDWP packet size (64 MiB) with serialized readPacket/writePacket I/O, and ensures stopListening and bounded process cleanup across timeout/error paths.
Packaged com.microsoft.java.debug.plugin-0.53.2.jar into a vscjava.vscode-java-debug.vsix paired with microsoft/vscode-java-debug#1736 and verified end-to-end in VS Code 1.147.0 with redhat.java across launch (breakpoints, stack trace, UTF-8 local variables, evaluate, stepping), noDebug: true, and loopback attach.
…raming
- Replace the shared wildcard debug server socket with per-session loopback
(127.0.0.1) server sockets, a 256-bit JavaDebug-Auth handshake with
constant-time verification, single-client socket closure, and an unused
session timeout reaper (protocolVersion >= 2 via startDebugSession).
- Enforce initialize lifecycle gating in DebugAdapter before request
argument deserialization, guard AttachRequestHandler against uninitialized
contexts, and prevent self-PID termination in DebuggeeProcessHelper.
- Slice inbound Content-Length frames by UTF-8 byte length rather than UTF-16
character count in AbstractProtocolServer, with header and body size bounds.
- Bind JDI launch listening sockets strictly to 127.0.0.1 via
LoopbackSocketListeningConnector with debugger-first JDWP-Handshake
validation and guaranteed stopListening cleanup across launch error paths.
- Add unit and OSGi end-to-end regression tests covering authentication,
framing, initialization gating, loopback JDI listening, launch,
oDebug,
and �ttach flows.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
On BSD/macOS kernels, closing a socket while unread client bytes remain in
SO_RCVBUF sends a TCP RST (SocketException: Connection reset) rather than a
FIN (-1 EOF). Accept either EOF or SocketException after connect when verifying
that unauthenticated or invalid-token sockets are closed without emitting any
DAP response.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved issues allow an unauthenticated local peer to trigger a roughly 2 GiB allocation, leave listeners open after executor rejection, and prolong the handshake far beyond its intended timeout.
This PR hardens the Java debugger’s session transport and launch connections, alongside the companion client update in microsoft/vscode-java-debug#1736.
Changes:
Adds authenticated, single-client loopback sessions with unused-listener expiry and shutdown cleanup.
Enforces initialization gating, guards against self-process termination, and makes DAP framing byte-accurate with size limits.
Introduces a loopback JDI listener and adds transport, lifecycle, and end-to-end tests.
…ner cleanup
- Enforce an upper JDWP packet-size bound (64 MiB default) in
LoopbackSocketConnection.readPacket() and close the connection before
allocating oversized buffers.
- Enforce an absolute wall-clock deadline across performJdwpHandshake() reads
so slow-drip peers cannot stretch per-read SO_TIMEOUT.
- Remove and close session listeners when executor submission throws in
startDebugSession() and startLegacyLoopbackSession().
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved critical issues allow worker-pool starvation, authentication handshakes to exceed their intended deadline, and concurrent reads to corrupt the JDWP stream.
readInt() throws EOFException when the debuggee closes between packets, but this catch converts it to ClosedConnectionException even though the connection has not been closed locally. The JDI Connection.readPacket() contract requires an empty byte array for clean EOF and an IOException for a truncated packet. Please distinguish those cases instead of treating every header-read failure as a closed connection (https://docs.oracle.com/en/java/javase/23/docs/api/jdk.jdi/com/sun/jdi/connect/spi/Connection.html).
…e JDWP I/O
Separate listener, handshake, and session worker pools with per-listener candidate permits, enforce an absolute authentication handshake deadline across reads, and serialize JDWP socket packet reads and writes while preserving mid-packet EOF errors.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Close the JDWP listener immediately on launch failure, drain debuggee stdout/stderr asynchronously with bounded timeouts while terminating the child process, and drain javac output asynchronously in end-to-end test compilation.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
An accept-side runtime exception can complete the result after losing the outcome claim, replacing the process-exit handler’s intended exit-status and diagnostic LaunchException.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because automated tests do not exercise terminal launches, leaving asynchronous listener cleanup and launch-future completion unverified across success and failure paths.
Overall the hardening looks solid! One suggestion around observability for the new hardcoded timeouts:
Both JavaDebugServer.DEFAULT_HANDSHAKE_TIMEOUT_MS (5_000 ms) and LoopbackSocketListeningConnector.DEFAULT_HANDSHAKE_TIMEOUT_MS (5000 ms) are newly introduced constants, and currently it's hard to tell from telemetry whether 5s is too tight in slower environments (e.g., high CPU load, AV scanning, or slow JVM startup):
JDWP handshake timeout vs. accept timeout: In LoopbackSocketListeningConnector, both accept() and performJdwpHandshake() throw TransportTimeoutException, which makes them indistinguishable in existing exception telemetry. Could we emit a dedicated telemetry/usage signal (e.g. via the existing telemetry event / UsageData path) when performJdwpHandshake() times out (and ideally record handshake duration on success) so we can track the timeout rate and tune DEFAULT_HANDSHAKE_TIMEOUT_MS based on real data?
Optional configurability: Having a system property override (similar to MAX_JDWP_PACKET_PROPERTY) as an escape hatch could also help if users hit unexpected 5s handshake timeouts before a fix ships.
(I'll leave a companion note on microsoft/vscode-java-debug#1736 to track the DAP auth handshake success rate and duration on the client side, since pre-session socket closures happen before ProtocolServer starts.)
Record structured `jdwp handshake` usage telemetry (`outcome`, `duration`, `timeoutMs`)
inside `LoopbackSocketListeningConnector.performJdwpHandshake` and allow overriding
the 5-second DAP and JDWP handshake timeouts via `java.debug.dap.handshakeTimeoutMs`
and `java.debug.jdwp.handshakeTimeoutMs` system properties.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because a breakpoint test failure can close the DAP socket without terminating the launched JVM, potentially leaving it suspended.
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
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.
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
6e6e436817bb515bff309ad0a0375d64e0b75702127.0.0.1sockets, constant-time 256-bitJavaDebug-Authverification under an absolute deadline, isolated listener/handshake/session worker pools, immediate listener closure after one authenticated client, and a 30s unused-session reaper.↑ Enforces
initializelifecycle gating prior to argument deserialization, byte-accurate UTF-8Content-Lengthframing, and loopback-only JDI launch listening with boundedJDWP-Handshakeand packet sizes.↓ Paired
protocolVersion: 2session negotiation requires companion client PRmicrosoft/vscode-java-debug#1736when bundling the updated server plugin JAR.ServerSocket(0)binding inJavaDebugServerand JDISocketListeningConnector, missing pre-initializecommand gating inDebugAdapter, andStringUTF-16 character slicing inAbstractProtocolServer../mvnw -B clean verify), and live end-to-end.vsixverification in VS Code acrosslaunch,noDebug, andattachworkflows.Summary
Companion server changes for microsoft/vscode-java-debug#1736. Hardens Debug Adapter Protocol (DAP) session transport,
initializelifecycle enforcement, UTF-8 message framing, and JDI launch socket binding.Changes
Per-session loopback DAP server & handshake authentication
JavaDebugServer.java,IDebugServer.java,JavaDebugDelegateCommandHandler.java,JavaDebuggerServerPlugin.java127.0.0.1ServerSocketpervscode.java.startDebugSession(protocolVersion >= 2), verifies a 256-bitSecureRandomJavaDebug-Authheader viaMessageDigest.isEqualwithin an absolute handshake deadline, closes the listener once a single valid client authenticates, expires unclaimed sessions after 30 seconds, isolates listener/handshake/session worker pools with per-listener candidate bounds, and rejects unversioned 0-argstartDebugSessioncalls by default.DAP
initializelifecycle gating & PID safetyDebugAdapter.java,ErrorCode.java,AttachRequestHandler.java,DebuggeeProcessHelper.javainitializecommands (exceptdisconnect) beforeinitializecompletes, rejects duplicateinitializerequests, defersJsonUtils.fromJson(...)payload deserialization until lifecycle gates pass, and guards process termination against self-PID (ProcessHandle.current().pid()).UTF-8 byte-accurate DAP framing
AbstractProtocolServer.javaContent-Lengthheaders and JSON payloads over raw UTF-8 byte counts instead ofStringUTF-16 code units, with bounded header (8 KiB) and payload (32 MiB) limits.Loopback-only JDI launch listener & bounded cleanup
LoopbackSocketListeningConnector.java,AdvancedVirtualMachineManager.java,AdvancedLaunchingConnector.java,LaunchCommandHandler.java,LaunchWithDebuggingDelegate.java127.0.0.1, performs debugger-firstJDWP-Handshakeverification under an absolute deadline, caps incoming JDWP packet size (64 MiB) with serializedreadPacket/writePacketI/O, and ensuresstopListeningand bounded process cleanup across timeout/error paths.Verification
./mvnw -B checkstyle:checkand./mvnw -B clean verifypassed (63 core tests + 33 plugin OSGi tests, includingDebugAdapterInitializationTest.java,AbstractProtocolServerTest.java,JavaDebugServerTest.java,LoopbackSocketListeningConnectorTest.java, andJavaDebugEndToEndFunctionalTest.java).com.microsoft.java.debug.plugin-0.53.2.jarinto avscjava.vscode-java-debug.vsixpaired with microsoft/vscode-java-debug#1736 and verified end-to-end in VS Code1.147.0withredhat.javaacrosslaunch(breakpoints, stack trace, UTF-8 local variables,evaluate, stepping),noDebug: true, and loopbackattach.