Repository navigation
Ariadne: host network policy and host-owned credentials (nicotina L1, L2) - #888
Conversation
An async call is charged its kernel's wall time against max_time and its CPU time as steps (docs/STATE_EXEC_EXCEPTIONS.md 3.8). For a kernel that waits on the network that charges the process for the round trip and for the host's transport. One HTTPS request measured about 16-18 ms of CPU (130,000-145,000 steps at the default 8000 a CPU ms: the TLS handshake and the CA store) and 180 ms of wall time, and the first localhost request of a process 13,500 steps. An Ariadne action's default budget is 5000 steps and 0.1 s, so no document could make one request. - async_options::io (off by default): the call's run time, CPU time and unmetered time read 0, so it is charged its one step. The function's own bounds limit it instead (a transport's timeouts and size cap, async_options::timeout). - STATE_EXEC_EXCEPTIONS.md 3.8 says so. - AnIoCallIsChargedItsOneStep: on both schedulers, a CPU-bound and a sleeping I/O call finish under a budget (1000 steps, 0.1 s) that the same work as plain calls runs out of; each is charged one step and no time.
parse_host_args, the command line ari and arigl share, walked argv by hand. boost::program_options now does the reading: it splits --flag=value and --flag value, knows which flags take a value, and rejects an unknown flag, one missing its value, or a value given to a bare flag (--ansi=1). Two rules stay this file's own: the first argument that is not a flag (or the one after "--") is the document, and it and everything after it are the document's, never the runtime's; and a repeated flag's last value wins while the repeatable ones collect. One change in behaviour: program_options' guessing is off, so an abbreviated flag (--comp for --component-path) is an unknown option rather than a guess. All 20 ariadne_host_test cases pass unchanged. libcvc links Boost::program_options with its other Boost components, and its exported config asks for it. cvc-cli already used it; the cvcpkg boost bundles carry it on every platform, wasm and wasm-mt included.
Items L1 and L2 for nicotina (cy-pca/nicotina docs/ROADMAP.md): a stock ari or arigl, given only
flags, lets a document reach the origins it allows and sign in without ever holding the token.
Nothing changes without the flags: no host registered the net verbs or the http(s) URI handler
before, and none does now unless told to.
L1, the allowlist (cvc/net/net_policy.h, cvc/ariadne/net_host.h):
- Flags before the document, in ari and arigl (window, terminal, browser): --net, --net-allow
ORIGIN (repeatable), --net-policy FILE (allow and credential lines) and --credential-store S.
Each implies --net. In a browser the page's own origin is allowed too.
- enable_net builds the allowlist and registers the http verbs and the http(s) URI handler with
it. cvc::net::send(req, policy) refuses a request to an origin the policy does not allow and
follows redirects itself, checking each hop and dropping Authorization, Cookie and
Proxy-Authorization on a cross-origin one. URLs are parsed strictly (http/https, no user info,
backslash, space or control byte, an ASCII host), so the origin checked is the one dialled.
- AppRuntime::enable_net / AriRuntime::enable_net for other hosts; the runtime turns it off as it
dies. register_net_intrinsics(app) alone is still the unchecked, credential-free form.
- The capability tokens net, net.auth and net.auth.persist, so requires: fails clearly where the
launcher did not turn the network on. ari/arigl info show the allowlist.
L2, credentials (cvc/net/credentials.h):
- A request's auth: "NAME" has the host add "Authorization: Bearer <token>" as it is sent, only to
an origin the credential is bound to; elsewhere the request is not sent. capture_auth: {name,
field} keeps the JSON string at field from a 2xx reply and puts "[redacted]" in its place, every
other byte unchanged. Any echo of a token in a reply is blanked. Neither option follows a
redirect. Tokens never become a value_t, so they reach no program variable, no state node (which
a state transport replicates) and no error message.
- A credential is bound to the origin it came from, or to the origins a policy's credential line
names. Tokens are RFC 6750 bearer tokens of 16-4096 characters.
- net-auth-has?, net-auth-forget, net-auth-clear and net-allowed?.
- --credential-store keeps them across runs: a name is a file in the user's config dir
(~/.config/cvc/credentials/, %LOCALAPPDATA%\cvc\credentials), anything else a path; one
"<name> <origin> <token>" line each, written 0600 in a 0700 directory and replaced whole. A file
another user owns or others can read is refused. A browser keeps them in memory.
The reply dict gains content_type, header_map (lowercased name -> value) and captured. The verbs
are I/O calls (the previous commit), so a request is charged one step.
Tests:
- net_policy_test (new, 22): origins and what is refused, the policy file and its errors, the
checked send and its redirect rules (a fake transport, and two localhost servers end to end), the
credential store, its file's modes, round trip and refusals, the JSON capture and redaction.
- ariadne_runtime_test AriadneNetHost.* (8), against a localhost server shaped like txwtf: the
token kept out of the reply and of the whole state tree and sent by auth, sent only to a bound
origin, refused origins never contacted, forget and clear, a credential surviving a restart, the
tokens and requires:, refused configs, and a 300 ms reply under the default action budget.
- ariadne_host_test: the flags, their errors, and a flag after the document being the document's.
docs/ARIADNE.md: 10.2 (the reply, the I/O charge) and a new 10.3 (the flags, the allowlist, the
policy file, credentials); the 11 caveats no longer say no host registers http.
…ts for requests, and its tests nicotina runs in ari (FTXUI and tvision, over SSH too) as much as in arigl, so the ari path gets the same coverage. The flags were already the shared host_cli's and ari already turned the network on for every command; what changes: - ari snapshot, with the network on, drains after its frames until no async call has been in flight for three drains (at most 10 s), then prints the frame. Frames drain faster than a reply comes back, so a document that signs in and fetches showed nothing in one frame; now one frame does, which CI can render against a local test server. Without the network it is as before. - ari snapshot prints the programs' warnings after the frame, as arigl snapshot does. - ari --help and docs/ARIADNE.md 10.3: the flags hold for run, snapshot, check and info, with either backend; examples for ari, ari --backend tvision and arigl. - ari_net_test (new, 5): the built ari against localhost servers. A document needing the network fails without the flags and loads with them (FTXUI and tvision); a snapshot signs in, is sent the token, is refused elsewhere; a credential store carries the sign-in to the next run (0600); bad flags exit 2. Every run's stdout and stderr is checked for the token: a reply with a token that is not a bearer token, an unwritable store, an endpoint echoing the header and a program raising with the reply, the token sent to a server that is gone, and credential files ari refuses (malformed, open to others) all print none. - Boost::program_options joins the Boost components each in-tree directory re-imports (ari, arigl, arisrv, cvc-cli, cvcGL, pycvc), so cvc's public link evaluates there on every CMake.
…untested Checked against transfix/libcvc#888 (276afd54) and #887 (44e7ec1b). #888 can capture and send cvcpkg's access token, but leaves the refresh token visible to the document, cannot send a stored credential in a form field for the refresh, and has no way to supply a cvctok_ token. On the single-threaded wasm page the verbs run inline, and no browser test makes a request through #887's page with #888's flags.
clang-format and the C preprocessor both read an EM_JS body as C++ tokens, so the
`typeof location !== "undefined"` test was written out as `!= =`. Emscripten's JS optimizer
(acorn, at -O3) rejected that and the wasm ari link failed ("ari terminal backend (wasm, node)").
The test is now `typeof location == "object" && location && location.origin`, which survives
both. Rebuilt locally: the wasm ari links and the CI job's node checks pass (the baked tour's
snapshot, and `ari info --net --net-allow https://tx.wtf`).
|
cypkg (cy-pca/cypkg), a terminal client for cvcpkg registries written as
Three things are missing. Each is generic, not specific to cvcpkg, so it could go in this PR or a follow-up:
A note on the browser side: as far as I can tell, |
…r values, --credential-env cypkg (cy-pca/cypkg), a terminal client for cvcpkg registries written as .ari documents, signs in with cvcpkg's device pairing. Its token reply carries an access and a refresh token, a refresh is an RFC 6749 section 6 form POST, and CI uses an API token from the environment. #888's credentials covered one token per reply, sent as a Bearer header; these three generic additions cover the rest without a token ever reaching the document (#888 (comment)). - capture_auth takes a list of {name, field, optional} dicts, one credential each, all captured from the URL's origin. Every field is taken first and each token blanked wherever the reply carries it, then each is kept. A missing optional field is no error: a refresh reply need not rotate the refresh token. A name given twice is an error. captured is true when every required field was kept; error names the ones that were not. - A credential value, (dict "credential" NAME), as a form or headers dict value: the request is encoded with a random letters-and-digits placeholder in its place, and the host puts the token there as it is sent (percent-encoded in a form, as is in a header), only for an origin NAME is bound to, like auth; elsewhere the request is not sent. Echoes are blanked in both spellings. A query refuses one (URLs are logged). Any credential option turns off redirect following, and the origin is checked against the policy before any token is looked up. - --credential-env NAME=VAR (repeatable, implies --net, native only): enable_net holds the token in VAR as credential NAME for the run, through the new CredentialStore::provide: in memory, ahead of the file's token for NAME, never written, replaced by a capture. A policy credential line must bind NAME, so the launcher decides where it goes. An unset or empty VAR supplies nothing, so a launcher can always pass the flag; a malformed value stops the host without being quoted. ari/arigl info list the names it supplied. - ari and arigl --help, net_intrinsics.h and docs/ARIADNE.md 10.2 and 10.3 describe them. Tests: - net_policy_test: provide (bound names only, ahead of the file, never written, replaced by a capture, forgotten). - ariadne_host_test: --credential-env parsing and its errors. - ariadne_runtime_test, against a localhost registry: a device reply gives two credentials and a refresh with a form credential sends the refresh token (percent-encoded) and keeps the new access token, no token in the state tree; credential values only for bound origins, never in a query, a duplicate capture name refused; an environment token as a Bearer and as an X-Api-Key header, never in the store file, an unbound name and a malformed value refused, an unset variable harmless. - ari_net_test: the same device sign-in and refresh, and --credential-env, through the built ari, no output carrying a token.
…took §10.3 #888 added §10.3 (the host's allowlist and credentials) beside this branch's §10.3, so the merge left two. The JSON section is now §10.4, its links follow, and its http-get example says the host has to allow the origin.
From nicotina M0's notes on #888: - arigl snapshot (window and --terminal) did not wait for requests as ari snapshot does, so one frame showed a document's first frame; nicotina's tests passed --frames 60 instead. - ari's wait ended after three drains with no async call in flight. A program working between two requests (parsing a reply is a sliced data step, not an async call) looked idle then, and the snapshot could miss the second reply. AppRuntime::idle() is now "no async call in flight and no program step waiting to run" (async_scheduler::has_runnable), and AppRuntime::settle(step, max_seconds) runs a host's step until the document has been idle for three steps running, at most 10 s. ari snapshot, arigl's terminal snapshot (a drain) and its window snapshot (a whole frame, the PNG written after) call it when the network is on. - ari_net_test SnapshotWaitsThroughWorkBetweenRequests: a document that loops between two requests shows both replies in a one-frame snapshot. With idle() back at "no call in flight" it fails (the second is empty); the whole suite still runs in about 3 s. - arigl is built only through the wasm-mt tree here (no native VTK); it compiles and links. CI's cvcGL lanes build it natively. - ari and arigl --help and docs/ARIADNE.md 10.3 say so.
…dential-env (cypkg) (#895) * ariadne: several credentials per reply, credentials as form and header values, --credential-env cypkg (cy-pca/cypkg), a terminal client for cvcpkg registries written as .ari documents, signs in with cvcpkg's device pairing. Its token reply carries an access and a refresh token, a refresh is an RFC 6749 section 6 form POST, and CI uses an API token from the environment. #888's credentials covered one token per reply, sent as a Bearer header; these three generic additions cover the rest without a token ever reaching the document (#888 (comment)). - capture_auth takes a list of {name, field, optional} dicts, one credential each, all captured from the URL's origin. Every field is taken first and each token blanked wherever the reply carries it, then each is kept. A missing optional field is no error: a refresh reply need not rotate the refresh token. A name given twice is an error. captured is true when every required field was kept; error names the ones that were not. - A credential value, (dict "credential" NAME), as a form or headers dict value: the request is encoded with a random letters-and-digits placeholder in its place, and the host puts the token there as it is sent (percent-encoded in a form, as is in a header), only for an origin NAME is bound to, like auth; elsewhere the request is not sent. Echoes are blanked in both spellings. A query refuses one (URLs are logged). Any credential option turns off redirect following, and the origin is checked against the policy before any token is looked up. - --credential-env NAME=VAR (repeatable, implies --net, native only): enable_net holds the token in VAR as credential NAME for the run, through the new CredentialStore::provide: in memory, ahead of the file's token for NAME, never written, replaced by a capture. A policy credential line must bind NAME, so the launcher decides where it goes. An unset or empty VAR supplies nothing, so a launcher can always pass the flag; a malformed value stops the host without being quoted. ari/arigl info list the names it supplied. - ari and arigl --help, net_intrinsics.h and docs/ARIADNE.md 10.2 and 10.3 describe them. Tests: - net_policy_test: provide (bound names only, ahead of the file, never written, replaced by a capture, forgotten). - ariadne_host_test: --credential-env parsing and its errors. - ariadne_runtime_test, against a localhost registry: a device reply gives two credentials and a refresh with a form credential sends the refresh token (percent-encoded) and keeps the new access token, no token in the state tree; credential values only for bound origins, never in a query, a duplicate capture name refused; an environment token as a Bearer and as an X-Api-Key header, never in the store file, an unbound name and a malformed value refused, an unset variable harmless. - ari_net_test: the same device sign-in and refresh, and --credential-env, through the built ari, no output carrying a token. * ci: the wasm ari makes requests under node Nothing tested a request from the single-threaded browser build, where the verbs run inline and the fetch backend spins on emscripten_sleep. The "ari terminal backend (wasm, node)" job now does: - src/ari/tests/net_probe.ari signs in (two tokens from one reply), refreshes with the refresh token as a form credential, fetches with the refreshed token, and is refused another origin; net_probe_server.py stands in for the registry. - xhr-shim.cjs: a small XMLHttpRequest over node's fetch, enough for emscripten's Fetch.js, so the page's cvc::net fetch backend runs under node (which has fetch but no XMLHttpRequest). - CVC_ARI_WASM_TEST_DOCS (off by default) embeds src/ari/tests at /tests in the wasm ari; the job turns it on, runs the probe, checks the results and that no token reached the output. - The job also runs when src/cvc/net or inc/cvc/net change. Run locally with the cvcpkg emsdk 5.0.7: every check passes. * ari, arigl: snapshot waits until the document is idle, arigl too From nicotina M0's notes on #888: - arigl snapshot (window and --terminal) did not wait for requests as ari snapshot does, so one frame showed a document's first frame; nicotina's tests passed --frames 60 instead. - ari's wait ended after three drains with no async call in flight. A program working between two requests (parsing a reply is a sliced data step, not an async call) looked idle then, and the snapshot could miss the second reply. AppRuntime::idle() is now "no async call in flight and no program step waiting to run" (async_scheduler::has_runnable), and AppRuntime::settle(step, max_seconds) runs a host's step until the document has been idle for three steps running, at most 10 s. ari snapshot, arigl's terminal snapshot (a drain) and its window snapshot (a whole frame, the PNG written after) call it when the network is on. - ari_net_test SnapshotWaitsThroughWorkBetweenRequests: a document that loops between two requests shows both replies in a one-frame snapshot. With idle() back at "no call in flight" it fails (the second is empty); the whole suite still runs in about 3 s. - arigl is built only through the wasm-mt tree here (no native VTK); it compiles and links. CI's cvcGL lanes build it natively. - ari and arigl --help and docs/ARIADNE.md 10.3 say so.
Items L1 and L2 of nicotina's host roadmap (cy-pca/nicotina docs/ROADMAP.md; atx-crypto-club/txwtf docs/roadmap/ARIADNE_CLIENT.md): stock
ariandariglhosts get a network allowlist and credentials that stay in the host, switched on by command-line flags alone. With no flag the network stays off, as before.What a launcher gets
--net--net-allow ORIGINscheme://host[:port](repeatable; implies--net)--net-policy FILEallow ORIGINandcredential NAME ORIGIN...lines (repeatable)--credential-store S~/.config/cvc/credentials/(%LOCALAPPDATA%\cvc\credentialson Windows), or a path; written 0600; refused in a browserThese flags make
enable_net(inc/cvc/ariadne/net_host.h) do the following:http(s)://URI handler.Authorization,CookieandProxy-Authorizationon a cross-origin hop.net,net.authandnet.auth.persistnow hold, so a document'srequires:fails clearly when the launcher didn't turn the network on.The flags behave the same in
ariwith either terminal backend (FTXUI,--backend tvision, over SSH too) and inarigl(window,--terminal, browser), forrun,snapshot,checkandinfo. With the network on,ari snapshotwaits after its frames until the document's requests have come back (at most 10 s), so CI can render a document that signs in against a local server. It also prints the programs' warnings, asarigl snapshotdoes.AppRuntime::enable_netandAriRuntime::enable_netare the matching setters, and the network is turned off again when the runtime is destroyed.Credentials (L2)
(http-get url (dict "auth" "txwtf")): the host addsAuthorization: Bearer <token>as the request is sent, but only when the credential is bound to the URL's origin. Otherwise the request isn't sent and the reply saysno credential 'txwtf' for <origin> (sign in first).(http-request "POST" login (dict "form" ... "capture_auth" (dict "name" "txwtf" "field" "token"))): the host keeps the JSON string atfieldfrom a 2xx reply. The body comes back with"[redacted]"in that one place; every other byte is unchanged.net-auth-has?,net-auth-forget,net-auth-clear,net-allowed?.credentialline binds the name to a list of origins.value_t, so they never reach the state tree or a program variable, and no error string quotes one.Response headers (item 3)
The reply dict now also has
content_type,header_map(lowercased name to value) andcaptured, alongside{ok status body url headers error}.Two changes beyond the brief
state_exec::async_options::io. An Ariadne action's default budget is 5000 steps and 0.1 s, and an async call was charged its kernel's wall time and CPU. Measured here (Linux, Release):So no document could have made a single HTTPS request in a stock host. The existing tests didn't catch it because their fake transports cost nothing. With
ioset, a call is charged one step, and the transport's own timeouts and size cap bound it instead. The net verbs register with it. Decided (Joe, 2026-10-29): keepasync_options::io. The alternative was for hosts to raiseariadne.limits.*whenever the network is on, which loosens the guard for every action.host_clion boost::program_options, as asked. The existing flags behave as before (all ofariadne_host_testpasses), except that abbreviated flags are no longer guessed. libcvc now linksBoost::program_options, which is in the exportedfind_dependencyand in the Boost components each in-tree directory re-imports. The cvcpkg boost bundles have it on every platform, wasm included.Tests
net_policy_test(new, 22 tests): origin parsing and what it refuses, the policy file and its errors, and the checked send with redirect rules (a fake transport, plus two real localhost servers on different origins). It also covers the credential store: binding, capture, forget and clear, and the file's 0600/0700 modes, round trip, refusal of a group-readable file, and errors that never quote the token. JSON capture and redaction are covered too.ariadne_runtime_testAriadneNetHost.*(8 tests), run against a localhost server shaped like txwtf:authsends it;authgoes only to bound origins; disallowed origins are refused with no request made; echoes are blanked;requires: [net]follow the host;ari_net_test(new, 5): the builtarirun as a launcher would, against localhost servers:arirefuses (malformed, open to others). None prints it.ariadne_host_test: the network flags, their errors, and that a flag after the document is the document's.state_exec_async_calls_testAnIoCallIsChargedItsOneStep, on both schedulers.AriadneTfEditor.InlineSeedIsLocaleIndependent.aribinary, against a Python stand-in for txwtf:requires: [net, net.auth]fails the load, naming both;--net-allow, sign-in returns 200 andcaptured: true, the body shows"token": "[redacted]",/user/mereturns 200 with the injected token, andhttps://evil.exampleis refused;--credential-storesigned in from the file without the document seeing the token.ari(CI's "ari terminal backend" configure): built, and under nodeari.js info --net-allow https://tx.wtfshows the allowlist and tokens,--credential-storeis refused ("a browser host keeps credentials in memory only"), and the baked tour still renders;arigl, in the gallery configuration (examples on): built and linked.arigl(examples off) fails to link onemscripten_fetch_*with this PR alone, becauseenable_netnow pulls the fetch backend in. arigl-web + ari page: stock browser hosts that run .ari documents by URL; arigl and arigl-web packages #887 (the arigl packaging work) moves arigl's-sFETCH=1and-sASYNCIFYout of the examples block, which fixes it. No CI job builds that configuration.Not done here (follow-ups)
arisrvdoesn't usehost_cli, so it has no network flags.net-auth-forget.