Skip to content

Security

Pummelchen edited this page Sep 18, 2026 · 13 revisions

Home · Installation · Compatibility · Tools Reference · Architecture · Providers · Configuration · Reliability · Security · Monitor · Testing · Troubleshooting · Project Tracker


Threat model

web_open accepts a URL chosen by a language model and fetches it. That makes it the server's only path from untrusted input to the network, and therefore an SSRF boundary.

Threat Example
Reaching internal services http://192.168.1.1/admin, http://wiki.corp/
Cloud credential theft http://169.254.169.254/latest/meta-data/
Local file disclosure file:///etc/passwd
Obfuscated encodings http://2130706433/, http://0x7f000001/, http://127.1/, http://[::ffff:127.0.0.1]/
DNS pointing at internal space a public-looking name resolving to 10.0.0.5
Redirect-based bypass a public URL redirecting to a metadata address
A page that exhausts the stack markup nested 100 000 deep, in under a megabyte
Credential leakage into logs API keys inside query strings

Three layers of defence

String matching alone is insufficient: localtest.me resolves to loopback, and 127.1, 0x7f000001 and 2130706433 are accepted by some resolvers. Validation therefore happens at three points.

1. Lexical validation

Before any network activity:

  • Scheme allow-list. Only http and https. file:, data:, javascript:, ftp:, gopher:, ws: and everything else are rejected.
  • Credentials rejected. A URL containing user:password@ is refused outright: it is both an obfuscation vector and something the server must never forward.
  • Blocked names. localhost, *.localhost, *.local, *.internal, *.intranet, *.corp, *.lan, metadata, metadata.google.internal, instance-data and similar. A trailing dot is normalized first, so localhost. does not slip through.
  • Strict IP-literal parsing. Dotted-quad only. Shorthand and radix tricks (127.1, 1.2.3, 2130706433, 0x7f000001, 0177.0.0.1) are rejected rather than interpreted.
  • Hostname shape. Every label must be alphanumeric or hyphen and must not start or end with a hyphen; the name needs at least two labels and an alphabetic top-level domain. This rejects bare internal hostnames such as http://intranet/.

2. Resolution validation

The hostname is resolved and every returned address is classified. A name with one public and one private answer is rejected, because the connection could land on either.

A resolution failure is deliberately not treated as a policy denial: it is allowed through so the caller sees a genuine network error rather than a misleading "blocked" message.

3. Redirect validation

Automatic redirect following is disabled in URLSession — the delegate returns nil — and every hop is re-validated before it is requested. A redirect chain cannot walk past the policy.

A deliberate denial is never retried through the Jina Reader fallback, which would otherwise route around the policy entirely.

The connection is checked, not pinned

Validation and connection are two separate DNS lookups. URLSession resolves the host again when it connects, so a name whose answer changes between the policy check and the connect — a DNS-rebinding attack — can land on a private address. URLSession exposes no way to pin the address it connects to, and pinning would also break TLS certificate validation for the original hostname.

The connection is therefore checked after the fact. The fetch attaches a URLSessionTaskDelegate to the size-capped read and reads back URLSessionTaskMetrics.remoteAddress — for every hop, since every redirect hop is re-validated — and refuses the response body unless the address the connection actually used was one the policy resolved for that host.

  • The peer is compared as an address, not as a string, so ::1 and 0:0:0:0:0:0:0:1 are the same peer. A peer that will not parse counts as unvalidated.
  • It is detection, not prevention. The connection is still made; because web_open issues GET only, the side effects a blind request can cause are limited, and the attacker does not receive the response body.
  • The check runs exactly where the policy resolved addresses. With SEARCH_ALLOW_PRIVATE_NETWORK, an IP literal, or a name that did not resolve there is nothing to compare against and the connection is not checked — the policy has already allowed it. Two cases fail closed: a peer outside the validated set, and a connection the task reported no address for, because an unverified connection is what the check is for.

An earlier version of this page recorded the missing pin as an accepted limitation. The transport limitation is real and remains — what changed is that it no longer decides whether the attacker gets the content.


A page cannot exhaust the stack

Markup nesting is a denial-of-service vector independent of SSRF, and it is cheap to build: <div></p> repeated nests far deeper than it looks. MarkupDepth measures the nesting of a fetched document on the raw bytes, before it is parsed, and refuses anything past maximumNesting (512).

  • It models real parser behaviour rather than counting brackets. It keeps a stack of open element names and applies HTML's implied end tags: the block set closes an open <p>, li/dt/dd/option/optgroup close their own kinds, a heading closes a heading, <a> closes <a>, table structure closes within the innermost table, and a <tr> with no open section gets the parser's implicit <tbody>.
  • It errs toward refusing. A closing tag that matches nothing open closes nothing, exactly as a parser treats it, so it cannot be used to hide depth. Where the model cannot represent a name exactly it over-counts, and over-counting refuses a page rather than letting a deep one through.
  • It is a sound upper bound, which is the property that matters: the measure is never below the depth of the tree that is actually built. It is compared against the real tree SwiftSoup produces and is exact on 24 of 25 representative constructs.

The limit admits about 514 tree levels once the parser's implicit html/body pair is counted, against a measured failure threshold near 20 000 — roughly a 39× margin. The extraction walk is iterative as well, so the bound is not the only thing standing between a fetched page and the stack.


What is refused

Category Ranges
Loopback 127.0.0.0/8, ::1
Private 10/8, 172.16/12, 192.168/16, fc00::/7
Link-local 169.254/16, fe80::/10
Carrier-grade NAT 100.64/10
Multicast 224/4, ff00::/8
Broadcast 255.255.255.255
Unspecified 0.0.0.0, ::
Reserved 0.0.0.0/8, 240/4, 192.0.0/24, 198.18/15, 2001:db8::/32
Cloud metadata 169.254.169.254, 100.100.100.200, fd00:ec2::254

An IPv6 literal can carry an IPv4 destination, so the classifier unwraps the address it actually reaches before judging it: IPv4-mapped (::ffff:0:0/96), the deprecated IPv4-compatible ::/96, NAT64 (64:ff9b::/96), 6to4 (2002::/16) and Teredo (2001:0::/32, whose client address is stored inverted). Native checks run first, so ::1, :: and fe80:: are classified as themselves and never reach the unwrapping. This closes a real bypass: http://[::ffff:127.0.0.1]/ reached IPv4 loopback before the fix.


SEARCH_ALLOW_PRIVATE_NETWORK

Setting this to true lifts both the name restrictions and the address restrictions, so an internal wiki on a .corp name becomes reachable. It exists for deliberately internal deployments.

It does not lift the scheme allow-list: file:, data: and similar remain refused.

Enable it only when you intend models to reach internal hosts. It turns web_open from a public-web fetcher into a general-purpose network client.


Secrets

Property Implementation
Source Environment variables or a config file
Persistence None — never written back to disk
Logging Never logged; queries appear as a stable hash by default
Diagnostics web_search_status reports configuration state, never key material
Transport Headers, except Mojeek, where the API requires a query parameter

Mojeek's key necessarily travels in the request URL. That request is never logged with its URL, and tests assert that no credential appears in logs or tool output.

Provider failure messages are curated from the error code, never built from URLError.localizedDescription. That platform string can echo the failing URL, and a Mojeek key lives in the query string, so a diagnostic could otherwise carry a credential.

No credential belongs in the repository, and the committed tree is scanned for key-shaped strings during review.


The HTTP transport: no auth, by design

The HTTP transport has no built-in authentication and no TLS. That is a deliberate decision, not an oversight:

  • Loopback is the default. The server binds 127.0.0.1 unless --host says otherwise, so a default deployment is not reachable off the machine.
  • A non-loopback bind is allowed but warns. The server logs a warning at startup because it is serving unauthenticated MCP over the network.
  • The only supported exposed deployment is behind a TLS-terminating reverse proxy, which is also where authentication belongs and can be added. Both vendors require an https:// connector URL in any case.
  • Bearer-token auth in the server is deliberately out of scope. It is not planned and should not be assumed; the reverse proxy is the supported control point.
  • Only declared Host names are served. The transport validates the Host header against an allow-list derived from the bind address (loopback names, plus the machine's own addresses for a wildcard bind), so a browser page that resolves an attacker-controlled name to this machine is refused with 421 Misdirected Request — DNS-rebinding protection. A proxy that forwards a public name declares it with --http-allowed-host <host>; the list stays exact-match rather than being disabled.

This is a deliberate trade-off rather than an oversight: a name is declared, the allow-list is never disabled wholesale. See Compatibility for the transport rules.


Exposing the HTTP transport safely

The transport speaks plain HTTP and does not authenticate. The supported shape is a reverse proxy that terminates TLS and does the authentication, with the server itself left on loopback:

# The server answers only for the public name; every other Host is refused with 421.
SwiftWebSearchMCP --transport http --port 8080 --http-allowed-host search.example.com

A wildcard bind logs a warning and answers only for the names it can derive from that bind plus any you declare, so an undeclared name cannot reach the server even by accident. Bearer-token auth inside the server is deliberately out of scope: a proxy already has to be there for TLS.

Outbound behaviour

  • The server identifies itself honestly as SwiftWebSearchMCP/1.0.
  • It does not impersonate Chrome or Safari to defeat bot controls.
  • Scrapers are disabled by default and rate limited hard, precisely because their targets defend against automation. They are not down-weighted during fusion: RankFusion.Configuration.scraperWeight is 1.0 by deliberate design, because a lower weight would let a scraper's worst result outrank another provider's best.
  • Each provider is contacted only as often as a request requires: provider limits are treated as a ceiling, not a quota to consume.

Reporting a vulnerability

This is a public repository with issues enabled. Report suspected vulnerabilities there rather than in a public pull request.


Home · Installation · Compatibility · Tools Reference · Architecture · Providers · Configuration · Reliability · Security · Testing · Troubleshooting · Project Tracker

Clone this wiki locally