Network
rin.net.request is the only way data leaves the sandbox over the network, and the user decides every
request. There is no permission name for it: the manifest's net list is the request, and the user's network
level for the extension is the answer.
"net": ["api.example.com"]
const res = await rin.net.request({
method: "POST",
url: "https://api.example.com/v1/roll",
headers: { "content-type": "application/json" },
body: JSON.stringify({ expr: "2d6" }),
});
const data = JSON.parse(res.body);
Declared hosts
net lists exact host names, at most 32 (rules in The manifest). A request may go only
to a listed host, over HTTPS. Rin Chat checks the host against the list before looking it up, so an
extension cannot leak chat text through DNS by asking for <text>.example.com.
Listing a host grants nothing. The install dialog says: "Wants to send data to these sites: <hosts>. You will
see each request first." When the user turns the extension on, the listed hosts are part of what they approve:
an update that lists more hosts is off there until they turn it on again.
The user's levels
Each extension has a network level, set on its page in Settings > Extensions:
| Level | What happens |
|---|---|
| Blocked (every extension starts here) | Every request is refused with net_blocked. No dialog is shown. |
| Ask every time | Every request opens the review dialog first. |
| Allowed hosts | Requests to hosts the user allowed go at once; any other declared host opens the review dialog. |
Allowed hosts are per extension and per place it is turned on: "in this chat" or "in chats with <character>".
A host allowed in one chat is not allowed in another. The user can list and remove them, and add local
services (below), on the same page.
Over all of this, Block network for all extensions in Settings > Extensions refuses every request from every extension, whatever its level.
Removing an extension drops its network rules, with or without its data: a reinstall starts Blocked.
The review dialog
When a request needs the user, Rin Chat prepares it completely, then shows exactly what will be sent:
- the extension's name (marked Unreviewed when it is);
- the method and the full URL, percent-decoded for reading, with characters that could hide or reorder text shown as codes;
- the host, the port and every address the host resolved to, which are the only addresses the connection may use;
- every header on the wire, each marked as set by Rin Chat or by the extension (an
authorizationheader is masked until the user presses Reveal); - the body, formatted or as exact bytes, with any run of four or more words that repeats text from the chat highlighted as "Contains your chat". The dialog says this is a hint only: an extension can disguise text.
The user answers Deny, Allow once, or Always allow <host> in this chat (or in chats with
<character>), which adds the host to that place's allowed hosts and moves an "Ask every time" level to
"Allowed hosts". What runs is exactly what the dialog showed; nothing can be changed between the two.
Three denials in a row in a chat block that extension's network in that chat ("You denied <name> three
times in a row, so its network requests are blocked in this chat until you change its network setting."). The
streak resets when the user allows a request, and changing the level clears it everywhere.
A review left open when the chat closes, switches, or turns the extension off sends nothing.
User-started code and turn hooks
A dialog waits on the user, and a turn cannot wait. So:
- From
onCommand,onWidgetandonPanel, a request that needs the user opens the dialog and the call waits for the answer. The hook's deadline is paused while the dialog is open and while the allowed request runs. Requests from user-started code run one at a time, so dialogs follow each other. - From any other hook (
onBeforeAssemble,onReplyDone,onChatOpenand the rest), only a host the user already allowed in this place works. Anything else fails at once withnet_needs_approval, before any DNS lookup, and the attempt is logged as "needs approval" with an Allow this host link on the extension's page.
A common shape: fetch from a command and keep the result in storage or a chat variable, then use it from turn hooks.
What Rin Chat enforces
Whatever the level, every request is checked by Rin Chat's core, not in the page:
- HTTPS only, to a declared host. No IP addresses, no user name or password in the URL. The fragment is dropped.
- One DNS lookup, and every address it returns is checked. If ANY is loopback, private (10/8, 172.16/12, 192.168/16), link-local, carrier-grade NAT, multicast, broadcast, IPv6 unique-local, or reserved (documentation, benchmarking, 6to4 and the like), the request is refused: a mixed answer is what DNS rebinding looks like. IPv4-mapped and NAT64 forms are judged by the IPv4 inside.
- The connection is pinned to the checked addresses; certificates are still checked against the host name.
- No redirects are followed (a 3xx is the response), no cookies are kept or sent, no proxy, no
referer. HTTP/1.1. - Headers: Rin Chat sets
host,user-agent: RinChat-Extension/1,accept: */*(unless you setaccept), andcontent-lengthwhen there is a body. You may add up to 32 more; names are HTTP tokens up to 64 characters, values visible ASCII up to 4096, no duplicates. Refused:accept-charset,accept-encoding,access-control-request-headers,access-control-request-method,connection,content-length,cookie,cookie2,date,dnt,expect,forwarded,host,keep-alive,origin,referer,set-cookie,te,trailer,transfer-encoding,upgrade,user-agent,via,x-http-method,x-http-method-override,x-method-override, and any name startingproxy-,sec-orx-forwarded-. - Methods:
GET,HEAD,POST,PUT,PATCH,DELETE. A body is text up to 64 KiB, never onGETorHEAD;POST,PUTandPATCHwithout one send an empty body. - Caps: URL 8192 characters, response 512 KiB, 10 seconds to connect, 20 seconds in all. The response body is handed over as UTF-8 text, invalid bytes replaced.
- Rate: per extension, a burst of 5 requests, refilling at 15 per minute (
net_rate_limited).
Local services
A user can add a local service by host and port on the extension's page (a chess engine on
localhost:8123, say). Requests to exactly that host and port may use plain http:// and any address. A
manifest can never name one; only the user adds them.
Error codes
| Code | Meaning | What to do |
|---|---|---|
net_blocked | The level is Blocked, Block network for all extensions is on, or three denials in a row in this chat | Tell the user where to change it |
net_needs_approval | A turn hook asked for a host the user has not allowed here | Make the request from a command, widget or panel click |
net_denied | The user denied it | Respect it |
net_refused | A rule refused it before it went: an undeclared host, not HTTPS, an IP address, a private address, a forbidden or malformed header, a body on GET, a body too large, a bad URL | Read the network log for the exact rule |
net_failed | It went and failed: DNS, connection, timeout, a response over 512 KiB | Retry later |
net_rate_limited | Past the rate | Slow down |
denied means the extension is not turned on in this chat (or the user left it).
The network log
Every attempt, allowed or not, is a line in the extension's network log on its page in Settings > Extensions: the time, method, URL, the address it connected to, the status, the request and response sizes, the decision (allowed host, allowed once, denied, blocked, private address refused, too many requests, needs approval, or refused), and the exact rule when one refused it. The log never holds a request or response body. It is kept in memory, the newest 200 lines per extension, and mirrored to the developer console while Developer mode is on.
Opening links
rin.open.url(url) (permission open.url) is separate from the network: it asks the user to open a link in
their browser, showing the full address, from user-started hooks only. Nothing is fetched by Rin Chat. See the
API reference.
In tests
rinext test runs requests through the same rules with a fake server; see Testing.
It does not resolve DNS, so it cannot show the private-address refusals.