Skip to content

Only accept base protocol framing on the socket launcher - #305

Merged
tortmayr merged 2 commits into
masterfrom
socket-hardening
Nov 12, 2026
Merged

tortmayr merged 2 commits into
masterfrom
socket-hardening

Conversation

@tortmayr

@tortmayr tortmayr commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What it does

Defer injector and server creation until the incoming stream starts with a JSON-RPC base protocol header prefix.

  • Inspect the Content- prefix with the same case sensitivity as lsp4j.
  • Push the inspected bytes back before passing the stream to the JSON-RPC launcher.
  • Close connections with other prefixes or connections that end without sending data before creating an injector.
  • Add socket tests for framed requests, split headers, and connections that should not create a server instance.

Related TypeScript implementation: eclipse-glsp/glsp-core#47.

Part of: eclipse-glsp/glsp#1825

How to test

  • Verified locally: reactor compilation, Checkstyle, and all 6 socket launcher tests pass.
mvn -B -Pm2 -pl tests/org.eclipse.glsp.server.test -am -Dtest=SocketGLSPServerLauncherTest -Dsurefire.failIfNoSpecifiedTests=false test

Follow-ups

Changelog

  • This PR should be mentioned in the changelog
  • This PR introduces a breaking change (if yes, provide more details below for the changelog and the migration guide)

The base protocol framing resembles an HTTP request closely enough that
a request posted by a web page could be misread as a JSON-RPC message.

- Close a connection whose stream does not start with "Content-", the
  prefix of the only headers lsp4j parses. This rejects HTTP requests
  and any other traffic that is not a GLSP client. The peeked bytes are
  pushed back, so a regular client is unaffected.
- Close a connection whose peer hangs up without sending anything.
- Run both checks before creating the injector. The server instance used
  to be created on accept, so any connection allocated an injector and a
  server before a single byte had been read.
- Add a launcher test that drives a real socket.
- Size the peek buffer from the header prefix directly, since an
  overridden length could reject every client or throw on 0
- Log rejected connections on debug, so requests from web pages
  can't flood the log
@tortmayr
tortmayr merged commit 561608d into master Nov 12, 2026
7 checks passed
@tortmayr
tortmayr deleted the socket-hardening branch November 12, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant