Repository navigation
Ariadne: ws-send carries a credential the host puts in (stacked on #923) - #926
Merged
Merged
Conversation
added 8 commits
October 30, 2026 18:51
…ws-close) A document can follow a server that pushes changes instead of polling it. cvc::net gets a WebSocket client (ws_client.h) with two backends: libcurl's WebSocket API natively, so wss:// has the same TLS and proxy handling as https://, and the browser's WebSocket under Emscripten. Messages arrive whole in a queue; ws-poll takes what is there without waiting, for on_tick loops, and ws-recv waits on the background pool. The host's policy checks a ws(s) URL as its http(s) twin, and auth/headers/credential values work as for the HTTP verbs (natively; a browser WebSocket sends no headers). Documented in ARIADNE.md 10.5, with client tests against a Beast server and verb tests in ariadne_runtime_test.
…efore looping over them
The reader queued the Error event and then closed, so a recv on another thread could take the error while open() was still true; NetWsClient. AnOversizedMessageIsAnError failed about one run in five. Closing first matches the peer-close path, which clears open_ before it queues.
A browser's WebSocket can't send request headers, so a document in the wasm page could only authenticate a live feed by holding the token and sending it in a message, and documents never see tokens. Now (ws-send H MESSAGE) sends a dict or list as JSON (json-encode, compact), and a (dict "credential" NAME) anywhere in it goes out as the host's token for NAME, a JSON string: (ws-send h (dict "type" "hello" "token" (dict "credential" "txwtf"))) - The token is fetched for the origin the connection was opened and checked as (its URL's http(s) twin, now kept in the handle table), so credential bindings apply as for HTTP. It is put in on the host just before the send, with room reserved so no replace leaves a copy in a freed buffer, then wiped; a send error is redacted. - A name with no token at that origin, or a credential value on a host that keeps no credentials, is an error and sends nothing. - Each connection remembers the credentials it has sent (handshake auth and header values too), and ws-recv / ws-poll blank them to [redacted] in what they return, as perform() does for an HTTP reply, should the server echo one. - A string message is sent as it is, as before. Tests: AriadneNetHost.WsSendPutsInTheHostsTokenThatNoValueHolds checks, against LocalWsServer, that the server gets the substituted token while no state node, error or warning holds it, that an echo comes back redacted and that a missing credential sends nothing; the round-trip test checks plain JSON and a host without credentials. Spec: docs/ARIADNE.md section 10.5. Merges master for #883's builtin_json_encode.
…t/ariadne-ws-credential # Conflicts: # src/cvc/ariadne/net_intrinsics.cpp # src/cvc/tests/ariadne_runtime_test.cpp
…dential # Conflicts: # docs/ARIADNE.md # src/cvc/ariadne/net_intrinsics.cpp # src/cvc/net/ws_client.cpp # src/cvc/tests/ariadne_runtime_test.cpp
This was referenced Oct 31, 2026
transfix
pushed a commit
that referenced
this pull request
Nov 6, 2026
…ter, without #925) This rebuilds the branch on master, which now has #923, #914 and #926, and drops the #925 merge: #925 (feat/ariadne-ws-nonblocking) is still open and fails its own AriadneNetL4.WebSocket* tests on macOS, which also failed this PR. This commit's tree is master plus the feature alone; its first parent keeps the branch's earlier history, so nothing is rewritten. A browser's WebSocket can send no request headers, but it can offer subprotocols, so a credential there is the one handshake auth a document in the wasm page can use. ws-open takes two new options: - "protocols": a list of subprotocols to offer (Sec-WebSocket-Protocol), each an HTTP token. - "auth_protocol": (dict "credential" NAME ["prefix" P] ["encoding" "raw"| "base64url"]) offers the host's token for NAME, fetched for the URL's origin as for auth, as one more subprotocol: P then the token, or its unpadded base64url (a token68's '/' or '=' can't be in a subprotocol), as Kubernetes does with "base64url.bearer.authorization.k8s.io.". cvc::net: WsOptions::protocols is sent natively as a Sec-WebSocket-Protocol line and in the browser through createAttributes.protocols. Both fail the connect unless the server picks one of the offered subprotocols, as browsers do (RFC 6455 4.1; natively from the 101's headers, which libcurl files under CURLH_1XX). An invalid or repeated subprotocol is refused, with no error quoting one, and the joined strings are wiped. ws_valid_protocol is public for the option checks. The token is wiped after the connect, and errors are redacted of it and of its base64url spelling. The connection records the name, so ws-recv and ws-poll blank either spelling if the server echoes it. Tests: NetWsClient covers offering, a server that picks none or another subprotocol, and invalid subprotocols. AriadneNetHost. WsOpenOffersTheHostsTokenAsASubprotocol checks the handshake line, the redacted echo, a raw token with '/' that is refused without connecting, and that no state node holds the token. LocalWsServer can pick a subprotocol. Spec: docs/ARIADNE.md section 10.5.
transfix
added a commit
that referenced
this pull request
Nov 11, 2026
Master moved ws-open and ws-recv on since this branch began: subprotocols and an auth_protocol credential (#928), credentials in ws-send and blanked in what ws-recv and ws-poll return (#926), connections kept as WsEntry with their origin. The non-blocking split is put back on top of that: - build_ws_open takes master's protocols and auth_protocol; prepare_ws_open puts the auth_protocol token in as a subprotocol; finish_ws_open files a WsEntry with the names of the credentials it sent. WsPrepared wipes its tokens when it goes, so a started connect that is abandoned leaves none behind either. - ws-recv's started wait scrubs the event as the kernel does. Its callback keeps the origin and the sent names, not the connection that holds the callback. - The browser's started connect (ws_start) checks and offers the subprotocols as master's ws_connect does. And the macOS failure: libcurl there has no WebSocket support, so have_ws_backend() was false, the ws-* verbs were never registered, and AriadneNetL4's two WebSocket tests never reached their connector. A connector set_ws_connector puts in place now counts as a backend; the libcurl connect still checks only what libcurl was built with.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #923 (
feat/ariadne-websocket).A browser's WebSocket can't send request headers. So until now, a document in the wasm/xterm.js page could authenticate a live feed (txwtf's
/ws/events, cvcpkg's/v1/live/wshello) only by holding the token itself, and documents never see tokens. With this change the host puts the token into the message.What changes
(ws-send H MESSAGE)builtin_json_encode, state_exec: json-parse, json-encode and state-set-tree, so documents can read REST replies #883's rules).(dict "credential" NAME)at any depth goes out as the host's token forNAME, as a JSON string. This is the same placeholder mechanism (CredentialValue,placeholder()) that HTTP forms and headers use.token_for(name, origin), so a credential bound to other origins is not sent. The policy is checked again before a credential goes out.send_text. Capacity is reserved up front so noreplacereallocates and leaves a copy in a freed buffer.authand header values atws-open, plusws-sendcredential values.ws-recvandws-pollblank those tokens to[redacted]in what they return, asperform()does for HTTP replies. The names are shared with aws-recvalready waiting, so a reply to an auth message sent during the wait is blanked too.ws client: close before queueing the oversized-message error: the curl reader queued the Error event beforeclose()clearedopen_. SoNetWsClient.AnOversizedMessageIsAnErrorfailed about one run in five locally (6 failures in 30 runs). It now closes first, matching the peer-close path; 60 of 60 runs passed after the fix.Not in this PR
auth_protocoloption onws-open(a credential asSec-WebSocket-Protocol, which browsers can set throughcreateAttributes.protocols). The wasm connect path is being moved onto Ariadne L4: requests in single-threaded wasm don't stall the frame loop #914's async work infeat/ariadne-ws-nonblocking, which duplicates the emscripten create code. That option should land after that branch, so the two don't fight. No query-string credentials, by design.builtin_json_encode, whichfeat/ariadne-websocketpredates. Until Ariadne: WebSocket client verbs (ws-open, ws-send, ws-poll, ws-recv, ws-close) #923 picks up master or lands, this PR's diff against its base also shows state_exec: json-parse, json-encode and state-set-tree, so documents can read REST replies #883.Tests
Local build (Linux, GCC, Ninja, RelWithDebInfo, libcurl with ws):
ariadne_runtime_test: 220 passed, 1 skipped (AriadneTfEditor.InlineSeedIsLocaleIndependent).AriadneNetHost.WsSendPutsInTheHostsTokenThatNoValueHolds. AgainstLocalWsServer, it checks that:{"type":"hello","token":"<token>","also":[1,"<token>"]};WsVerbsRoundTripThroughAPolicynow also checks plain JSON, and the error on a host without credentials.net_ws_client_test: 8 passed (5 full runs, plus 60 runs of the previously flaky case).Spec: docs/ARIADNE.md §10.5.