Skip to content

Add an experimental module that binds sessions to the device with DBSC - #2009

Open
reiern70 wants to merge 1 commit into
masterfrom
device-bound-sessions-2008
Open

reiern70 wants to merge 1 commit into
masterfrom
device-bound-sessions-2008

Conversation

@reiern70

Copy link
Copy Markdown
Contributor

Closes #2008.

What

A new experimental module, wicket-experimental/wicket-dbsc, that binds a Wicket session to the device it was signed in on, following the Device Bound Session Credentials draft. It also adds a "device bound sessions" example in the authentication index of the examples.

protected void init()
{
	super.init();
	new DeviceBoundSessions().install(this);
}

// after a successful sign-in
DeviceBoundSessions.get().start();

How it works

  • The container's JSESSIONID is left alone: it lives as long as the HTTP session and cannot be made short-lived. A bound session needs a second cookie as well. That cookie lives 10 minutes by default and is scoped to the application's path (context path plus filter path).
  • install mounts a registration endpoint and a refresh endpoint and adds a request cycle listener.
  • start() sends Secure-Session-Registration on the current response, which can be a page, an Ajax response or the redirect after the sign-in form. The registration endpoint verifies the browser's proof, stores the public key in the Wicket session, returns the JSON session instructions and sets the bound cookie.
  • The refresh endpoint answers a request without a valid proof with 403 and a new Secure-Session-Challenge. A valid proof gets a new bound cookie. A session that no longer exists gets {"continue": false}.
  • The listener sends a request on a bound session without a valid bound cookie to onMissingCredential(). By default that rejects the request with 403 and leaves the session alone. Enforcement starts with the first bound cookie the browser presents, or after a 30-second grace period, because the registration races with the requests that follow sign-in.
  • Proofs are verified with the JDK alone: ES256 on P-256 and RS256 with at least 2048 bits. alg none, other JWT types and points off the curve are refused. The draft puts the JWK in the JWT header (§9.10), but its own example puts it in the payload, so both are read.
  • Browsers without DBSC ignore the header, and their sessions keep working unbound. Applications that do not install the module see no change.

Testing

  • 39 unit tests in the module, using WicketTester and a simulated browser that signs real ES256 and RS256 proofs, plus a test for the example application. mvn clean verify -Pjs-test is green.
  • Against Jetty over HTTP, with a WebCrypto P-256 key standing in for the browser: registration, rejection of a replayed JSESSIONID, refresh with a challenge, refusal of a proof from another key, and {"continue": false} for a session that is gone.
  • Chrome 155 on Linux receives the header but does not register, even with DeviceBoundSessions:RequireOriginTrialTokens/false and the software-keys flag. A run in a real browser still needs Chrome 146+ on Windows. If someone has one at hand, the example at /devicebound uses a one-minute bound cookie, so refreshes are easy to watch.
  • In both Chrome and Firefox the example keeps working with the session unbound.

Open questions

  • Should a request without the bound cookie be rejected (the current default) or invalidate the session?
  • The draft is still an editor's draft. Is wicket-experimental the right home until it settles?
  • Not covered yet: federated sessions (provider_*), include_site, and races between cluster nodes during cookie rotation.

Device Bound Session Credentials (a W3C WebAppSec editor's draft) let a
server tie a session to a key pair the browser keeps on the device. Wicket
had nothing for it: a session cookie copied by malware works from any
machine until the session ends.

The new wicket-experimental/wicket-dbsc module adds it without touching the
container's session cookie, which lives as long as the HTTP session and
cannot be made short-lived. DeviceBoundSessions.install(application) mounts
a registration and a refresh endpoint and adds a request cycle listener.
DeviceBoundSessions.get().start(), called after sign-in, adds
Secure-Session-Registration to the current response, a redirect included.
Once the browser has registered a key, every request Wicket handles for
the session needs a second, short-lived cookie, scoped to the application's
path, which the browser only gets by signing a server challenge with that
key. A request without it is rejected with 403 through
onMissingCredential(), which an application can override. Enforcement
starts with the first bound cookie the browser presents, or after a grace
period, because the registration races with the requests that follow
sign-in.

Proofs are verified with the JDK alone: ES256 on P-256 and RS256 with at
least 2048 bits. alg none, other JWT types and points off the curve are
refused. The draft puts the JWK in the JWT header while its own example
puts it in the payload, so both are read.

Browsers without DBSC ignore the header and their sessions stay unbound.
Applications that do not install the module see no change. The examples
get a "device bound sessions" application in the authentication index.

The server side was exercised against Jetty over HTTP with a WebCrypto
P-256 key: registration, a replayed session cookie rejected, refresh with
a challenge, a proof from another key refused and a vanished session ended
with {"continue": false}. Chrome 155 on Linux receives the header but does
not register, even with the DBSC developer flags, so a run in a real
browser still needs Chrome on Windows. Chrome and Firefox both keep working
with the example unbound.

GitHub issue #2008
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.

Experimental support for Device Bound Session Credentials (DBSC)

1 participant