boxlang-express 0.2.4

Released .

  • Added java-src/boxexpress/ws/ — this project's first compiled Java, vendored as libs/boxexpress-ws-shim-1.0.0.jar (rebuild with java-src/build.sh). Exists because Undertow's own WebSocket receive extension point, io.undertow.websockets.core.AbstractReceiveListener, is an abstract Java class with protected hook methods, not an interface — confirmed directly, not assumed, that BoxLang can't work around that: its documented extends="java:X" feature for subclassing a Java class fails on the installed runtime (a constructor-argument- forwarding bug reproduced even with BoxLang's own docs example), and implementing the lower-level org.xnio.ChannelListener interface directly instead hits a wall too — its handleEvent fires fine, but the only way to actually consume a pending frame, channel.receiveFrame(), is protected and BoxLang's Java interop can't invoke it. BoxWebSocketListener.java does the real Java-side subclassing once and re-exposes every event through a plain interface, WebSocketMessageHandler, that BoxLang code implements via createDynamicProxy like everything else in this codebase already does. Every callback runs on its own virtual thread, not Undertow's I/O thread — confirmed necessary, not assumed, after a version without that intermittently reset the connection under a blocking call from inside the receive handler, same class of bug already fixed once for the HTTP request path. See tests/specs/WebSocketShimSpec.bx.
  • Added app.ws(path, callback) and WebSocketConnection — WebSocket routes, built on the shim above. A dedicated WsUpgradeRouter sits in front of Undertow's normal dispatch only when at least one app.ws() route is registered (an app that never calls it pays nothing extra); it delegates a matching Upgrade: websocket request to the WebSocket handshake handler and everything else — which is almost every request, even in an app that does use app.ws() — through the exact same HTTP dispatch chain, completely unchanged. An upgrade request to a path with no registered route falls through to that same chain and gets whatever it would otherwise return (a 404 if nothing else matches), rather than being silently accepted. WebSocketConnection's send()/close() are safe to call from another thread than the one that opened the connection — the same broadcast pattern and the same per-connection lock SseEmitter already uses, for the same reason. connection.headers/connection.cookies expose the handshake request's headers/cookies (mirroring req.headers/req.cookies), since app.ws() routes bypass the use() middleware chain entirely — a session cookie is otherwise unreachable from a WebSocket handler. See WebSocketConnection.bx and tests/specs/WebSocketRouteSpec.bx.
  • Added boxExpressStomp() / Stomp — a STOMP 1.2 pub/sub broker built entirely on top of app.ws(), no changes needed to the shim or the WebSocket routing layer above. StompFrameCodec.bx escapes header values (backslash/newline/colon) per spec rather than just stripping them — the protocol-correct version of the same injection fix SseEmitter.bx needed, applied here before it could ever become a bug instead of after. Deliberately smaller than some STOMP brokers' full feature set for a first version — no exchanges/bindings, transactions, client ACK/NACK, binary bodies, or full bidirectional heartbeat negotiation; see the STOMP docs for what's actually built and why the rest was deliberately deferred. Two real BoxLang bugs found and fixed while building this, both now documented in docs/ARCHITECTURE.md: a private method isn't reachable from a closure once that closure is invoked from outside the class that defined it (every helper Stomp.bx's handler closures call had to become a plain method because of this), and duplicate() can't deep-copy a struct holding a raw Java object reference — structCopy() (shallow) is what _deliver() actually needs. Security fix (found in review before this shipped): the shared subscriber registry was keyed on the client-supplied SUBSCRIBE id header alone, with no per-connection scoping — since STOMP subscription ids aren't secret (many client libraries assign them sequentially, e.g. sub-0), a second connection subscribing to the same destination with the same id silently overwrote the first connection's entry, redirecting the first connection's messages to the second with no error to either side, and let the second connection's UNSUBSCRIBE delete the first connection's subscription. Fixed by keying the registry on a server-generated per-connection id combined with the client's own subscription id, so no cross-connection collision is possible even when two clients choose identical ids. See Stomp.bx and tests/specs/StompSpec.bx.
  • Security fix: SseEmitter.send()'s event/id arguments and comment()'s text argument were concatenated directly into their SSE field lines with no newline stripping — unlike data, which is safely split per-line. An embedded char(10) in either let a caller that pipes request-derived input into event/id (a channel name, a correlation ID) have a client inject a fabricated data:/event:/id: line, or a blank line starting an entirely new, attacker-defined event, into the stream every other client reading it sees — a cross-client message- spoofing primitive, the same class of issue as CRLF injection in a response header value. Found in a security review, not by a report. event/id/comment()'s text are now stripped of char(13)/ char(10) before being written. See SseEmitter.bx.