boxlang-express 0.2.4
Released .
- Added
java-src/boxexpress/ws/— this project's first compiled Java, vendored aslibs/boxexpress-ws-shim-1.0.0.jar(rebuild withjava-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 documentedextends="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-levelorg.xnio.ChannelListenerinterface directly instead hits a wall too — itshandleEventfires fine, but the only way to actually consume a pending frame,channel.receiveFrame(), isprotectedand BoxLang's Java interop can't invoke it.BoxWebSocketListener.javadoes the real Java-side subclassing once and re-exposes every event through a plain interface,WebSocketMessageHandler, that BoxLang code implements viacreateDynamicProxylike 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)andWebSocketConnection— WebSocket routes, built on the shim above. A dedicatedWsUpgradeRoutersits in front of Undertow's normal dispatch only when at least oneapp.ws()route is registered (an app that never calls it pays nothing extra); it delegates a matchingUpgrade: websocketrequest to the WebSocket handshake handler and everything else — which is almost every request, even in an app that does useapp.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 (a404if nothing else matches), rather than being silently accepted.WebSocketConnection'ssend()/close()are safe to call from another thread than the one that opened the connection — the same broadcast pattern and the same per-connection lockSseEmitteralready uses, for the same reason.connection.headers/connection.cookiesexpose the handshake request's headers/cookies (mirroringreq.headers/req.cookies), sinceapp.ws()routes bypass theuse()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 ofapp.ws(), no changes needed to the shim or the WebSocket routing layer above.StompFrameCodec.bxescapes header values (backslash/newline/colon) per spec rather than just stripping them — the protocol-correct version of the same injection fixSseEmitter.bxneeded, 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, clientACK/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: aprivatemethod isn't reachable from a closure once that closure is invoked from outside the class that defined it (every helperStomp.bx's handler closures call had to become a plain method because of this), andduplicate()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-suppliedSUBSCRIBEidheader 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'sUNSUBSCRIBEdelete 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()'sevent/idarguments andcomment()'stextargument were concatenated directly into their SSE field lines with no newline stripping — unlikedata, which is safely split per-line. An embeddedchar(10)in either let a caller that pipes request-derived input intoevent/id(a channel name, a correlation ID) have a client inject a fabricateddata:/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()'stextare now stripped ofchar(13)/char(10)before being written. See SseEmitter.bx.