Network
host.net.fetch: HTTP made by the SpaceMIX server for the extension, limited to the hosts its net: permissions allow, with the limits, redirects and errors.
An extension's frame has no network: fetch, XMLHttpRequest and WebSockets are blocked by its content security
policy. HTTP goes through host.net, and the SpaceMIX server makes the request. CORS doesn't apply, and the
frame never touches the network itself.
The policy does let the browser load <img>, <audio>/<video> and <iframe> content from any http: or
https: URL, without a permission (see protocol.md). Everything your code reads goes through
host.net.
interface SpacemixHost {
net?: NetApi; // present with any `net:` permission
}
interface NetApi {
fetch(url: string, init?: NetRequest): Promise<NetResponse>;
allowedHosts(): Promise<string[]>;
}
interface NetRequest {
method?: string;
headers?: Record<string, string>;
body?: string | ArrayBuffer | Uint8Array;
timeout?: number; // ms, default 30 000
}
interface NetResponse {
ok: boolean;
status: number;
statusText: string;
headers: Record<string, string>;
text(): Promise<string>;
json<T = unknown>(): Promise<T>;
arrayBuffer(): Promise<ArrayBuffer>;
}
Permission: any net: permission (see permissions.md). Which hosts a request may
reach:
| Permission | Allows |
|---|---|
net:api.example.com |
exactly that host on the scheme's default port |
net:example.com:8443 |
that host on port 8443 |
net:*.example.com |
any subdomain of example.com (a.example.com, a.b.example.com), not example.com itself |
net:* |
any host the user allows; the user is asked the first time each new host is reached |
Hosts compare case-insensitively. A host on a non-default port must be listed with its port.
host.net.fetch
fetch(url: string, init?: NetRequest): Promise<NetResponse>;
Makes one HTTP request and resolves with the whole response, already read. Bridge method: net.fetch.
Request.
url: absolutehttp:orhttps:URL.method: defaultGET, upper-cased.headers: sent as given, except connection-level ones, which are dropped:connection,keep-alive,proxy-authenticate,proxy-authorization,proxy-connection,te,trailer,transfer-encoding,upgrade,host,content-length,accept-encoding. Setcontent-typeyourself for a JSON body.body: a string is sent as UTF-8 text;ArrayBufferandUint8Arrayas bytes.FormData,Bloband streams aren't supported; encode them yourself.timeout: milliseconds for the whole request, redirects included. Default 30 000, at most 120 000 (larger values are clamped). The frame itself puts no limit onnet.fetch, since it may first wait for the user to allow the host.- No cookie jar: cookies are never stored between requests. Send them yourself if a server needs them.
Redirects are followed by the server, up to 10, and every hop is checked against the permissions like the
first request. As browsers do, a 303 (and a 301 or 302 after a POST) becomes a GET without a body.
Authorization and Cookie are not sent on to a different host.
Response.
okis true for status 200–299. A 4xx or 5xx resolves withok: false; it doesn't reject.statusTextis the standard reason phrase for the status, not the server's own text.headershave lower-case names; repeated headers are joined with", ". Connection-level headers are left out.text(),json()andarrayBuffer()can each be called any number of times.- The body is not decompressed (
accept-encodingisn't forwarded, so servers normally send it plain). - At most 20 MB. A larger response rejects.
Limits. Response 20 MB. In a browser, the request travels to the server as JSON with a 30 MB limit, so a binary body (base64-encoded on the way) should stay under about 20 MB.
Errors. fetch rejects (rather than resolving with a status) when no response came back:
| When | Message (example) |
|---|---|
| The host isn't allowed | Not allowed to reach example.com or <Name> isn't allowed to reach example.com |
| The person may not use this extension (who can) | You don't have access to <id>. |
| The extension is a paid one, turned off on the server (turned off) | <Name> is turned off on this server until it's paid for. |
| The server's network switch for the extension is off (Settings → Extensions → Data leaving, below) | Not allowed to reach example.com: network access is turned off for this extension on this server. or <Name> isn't allowed to reach example.com: its network access is turned off on this server. |
| The same, for a request whose URL has no usable host | <Name> isn't allowed to reach the network: its network access is turned off on this server. |
| Not an http(s) URL | Only http and https URLs can be reached, not ftp: |
| Not a URL | "foo" isn't a URL. |
| Invalid method, header name or value | Invalid method: …, Invalid header name: …, Invalid value for header … |
| Connection failed (DNS, TLS, refused) | Couldn't reach example.com: … |
Took longer than timeout |
The request timed out. |
| More than 10 redirects | Too many redirects. |
| Response over 20 MB | The response is larger than 20 MB. |
Public addresses only
A Studio preview and a member's own build, always, and every extension on a hosted server, reach only public addresses: on the first request and on every redirect the host is resolved, refused if any of its addresses is loopback, private or otherwise not public (the same check as widgets' web sources), and the connection goes to the checked addresses so a second lookup can't move it. A refusal rejects with <Name> isn't allowed to reach <host>: it isn't a public address, and the server's owner hasn't exempted it. and is logged as private-address.
Only the owner can exempt a host (GET and PUT /api/extensions/net-exemptions with { "hosts": [...] }, at most 50, spelled like a net: permission's host). An exempt host skips this rule, not the rest: the extension still needs a net: permission or grant that covers it.
Everything else on a self-hosted server or the desktop app can reach what its permissions name, private addresses included.
The net:* prompt
With net:*, the first request to a host the extension hasn't reached before opens a dialog in the window that
made the request ("allow this extension to reach host?"):
- Concurrent requests to the same host wait on the same question.
- Allow stores the host as a grant on the installed extension (
POST /api/extensions/grant-host, which only someone who may use the extension can call). Grants belong to the server's install, so the host is then allowed for everyone on the team who uses the extension, from every window, without asking again. - Don't allow rejects the request with
Not allowed to reach <host>, and requests to that host fail at once for the rest of that window's life (reload the app to be asked again). - Grants are per
host[:port]. Each subdomain is asked about separately. - A grant can be taken back with
POST /api/extensions/revoke-host({ id, host }, the same access as granting; IPCextensions_revoke_host). The next request to that host asks again.
The same check covers MCP servers (see mcp.md). In the Studio preview, grants last only as long as the window.
What the server logs, and the network switch
The requests the server makes for an extension (host.net and host.git) are written to its egress log, the
core table egress_log (apps/desktop/src-tauri/src/egress.rs):
- One row per
host.netrequest and redirect hop, and one per git connection (clone, fetch, or a read that downloads file contents; methodgit). - One row per attempt the server refused before anything left (
refused:not-declaredfor a host no permission or grant covers,network-off, orunpaid). - A row has the extension's id, the host (
host[:port]), the method, the response's status (none when refused, when the connection failed or timed out, and for git), the bytes sent (the URL's path and query, each header's name and value, and the body;0for git, which doesn't say), the response body's bytes (for git an approximation: what its local copy grew by; a git download that fails part-way may not be recorded at all), whether it was a preview, and the time. - It never has the URL's path or query, a header, a body, or who sent the request. A request sent with a
client-supplied
preview(a Studio preview, or anything that passes one toPOST /api/ext/fetchor the git routes) is markedpreview, nothing more. - Rows are kept 30 days, and at most 10,000 per extension (the oldest go first), so for a very busy extension the
log of individual requests can cover less than 30 days. The per-host totals (
egress_daily, one row per extension, host and UTC day) are kept the full 30 days whatever the cap drops, so a host never disappears from the summary within them.
The app's window tells the server which extension a request is for (the extension of POST /api/ext/fetch, the
extension and preview of the git routes). A signed-in person calling /api/ext/fetch or /api/git/* directly
can name any extension, or none for git, and the app's own git calls, made for no extension, aren't logged.
Widgets' web sources, which the server fetches itself (apps/desktop/src-tauri/src/widget_net.rs),
are logged the same way under the id core.widgets (core.widgets is one of the ids reserved for SpaceMIX itself, so no extension can be installed with it): one row per hop that goes
out, and refusals as not-declared (a URL the rules refuse, one no widget declares, a private or unresolvable host)
or network-off; never preview. A refusal has a row only when the string parses as a URL with a host: one that
isn't a URL, or has no host, is refused without a row, and so is a request refused because the widgets couldn't be
read. Answers from their 30-second shared cache, and requests refused for the rate limit, aren't logged. The network switch for core.widgets turns every web source off, with
Widgets aren't allowed to reach the network on this server. in place of the data. Data leaving always has a
row for it, Widgets, with its switch.
Only requests that reach the server are logged. Every refusal made in the window is not: a host no permission
covers, the network switch, and a net:* host the person said no to. Neither are MCP calls (the window makes them
itself, see mcp.md), prompts sent through host.ai, links opened with host.shell.openUrl, nor what
leaves the frame through images, media or nested pages (see protocol.md)
or WebRTC (see media.md).
People with server:settings read it: GET /api/egress/summary?days=7 (1 to 30 whole UTC days, default 7, built
from the per-host totals) answers
{ extensions: [{ id, networkOff, hosts: [{ host, requests, refused, previewRequests, bytesOut, bytesIn, lastAt }] }] }
for every installed extension (hosts: [] when it sent nothing) and any other id with traffic, such as a Studio
preview; requests counts refused and preview requests too. GET /api/egress/log?extension=<id>&limit=100&before=<at>
answers { entries: [{ host, method, status, refused?, bytesOut, bytesIn, at, preview }] }, newest first (limit at
most 500, before an at for the next page; times are Unix milliseconds). Over IPC: egress_call with op summary
or log. Client: apps/desktop/src/lib/egress.ts.
The network switch turns an extension's network off for everyone on the server, Studio previews of the same id
included. People turn it in Settings → Extensions → Data leaving, which also shows people with server:settings the
summary and log above, and each extension's risk list. It is the kv key shell/networkBlockedExtensions (a list of extension ids), guarded like
media access: anyone with access may add an id, only people with
server:settings may remove one (Only people who may change server settings can turn an extension's network access back on.). A list that can't be read is treated as every extension's network being off, by the server and by
the window. While it is off:
- the server refuses
host.netrequests before connecting and logs them asnetwork-off; - the server refuses
host.gitadd(for a repository not added yet) andfetch, logged the same way, and reads run with every git transport turned off: what is already in the local copy can be read, anything else is refused; - the window refuses
net.fetchand MCP calls, the agent's included, on every call, with the messages in Errors.
The extension still loads and host.net is still present: requests fail as for a host that isn't allowed.
Not everything is enforced by the server. Taking back a grant (POST /api/extensions/revoke-host) and a person's
"no" to a net:* host are enforced only in the window: the server lets net:* reach any host, grant or not. The
switch is enforced in both.
host.net.allowedHosts
allowedHosts(): Promise<string[]>;
The hosts this extension may reach right now without being asked: every net: permission except net:* (with the
net: prefix removed, so *.example.com entries appear as written) plus the hosts users allowed since. Use it to
show "connected to …" or to decide whether a settings form should warn that a prompt will appear. Bridge method:
net.allowedHosts.
Example
import { host } from "@spacemix/sdk";
interface Issue {
number: number;
title: string;
}
export async function openIssues(owner: string, repo: string, token: string): Promise<Issue[]> {
if (!host.net) throw new Error("This extension needs the net:api.github.com permission.");
const res = await host.net.fetch(`https://api.github.com/repos/${owner}/${repo}/issues?state=open`, {
headers: { authorization: `Bearer ${token}`, accept: "application/vnd.github+json" },
});
if (!res.ok) throw new Error(`GitHub answered ${res.status} ${res.statusText}`);
return res.json<Issue[]>();
}
Stability
Stable. The exact wording of errors is not.