Skip to content

Server and security

yassinezerguine08 edited this page Oct 23, 2026 · 1 revision

The server and its security

The interface is served over HTTP on the machine itself, and the window is the only thing meant to talk to it. A loopback port is reachable by every other program on the machine and by every page in the person's own browser, so the server proves each request comes from the window it opened.

Starting it

final SessionToken token = SessionToken.random();
final UiServer server = new UiServer(Routes.create(application.id(), templates, token,
	window.control(), actions, index));
final URI uri = server.start();   // such as http://127.0.0.1:53817/
Property Why
Loopback only: it listens on 127.0.0.1 The interface acts for the person using it, so nothing off the machine can reach it.
A port chosen at random each start Another local program cannot guess the address ahead of time.

server.stop() stops it, and server.join() waits until it has stopped.

The session token

SessionToken.random() makes 32 random bytes, encoded for a URL. The window opens the first page with the token in the query:

window.open(uri.resolve("/?" + SessionToken.PARAMETER + "=" + token.value()));

What happens then:

  1. The guard sees the token in the query, sets it as a cookie and redirects to the same path without the query. The token does not stay in the address or in referrers.
  2. Every later request carries the cookie, and the guard admits it.
  3. A request without the token is refused with 403.

The cookie is named after the application's id, <id>-session, such as ledger-session. It is HttpOnly, so scripts in the page cannot read it, and SameSite=Strict, so no other site's page sends it. Cookies are kept per host and not per port, so apps with different ids keep their cookies apart even in one browser. The token is compared in constant time.

The origin check

Before anything else, the guard refuses a request whose Origin header is not the server's own address, with 403. A page open in the person's browser could otherwise send requests that act, even though it cannot read the answers.

What is served where

Path Answered by
/static/… Files under static/ on the classpath
/oriel/… Oriel's scripts: htmx.min.js, window.js, failure.js
/window/… Commands for the window; see The window
/action/<name> The application's actions; see Actions
anything else The index view, rendered afresh

All of it, files included, sits behind the guard.

Oriel's scripts sit under a root of their own, oriel/, because the classpath answers with the first folder of a name it finds, and the application keeps a static/ folder of its own.

Clone this wiki locally