module

MJ::Arcana::FetchReference

Fetch a reference image by URL.

Overlore sends a portrait with every panel and wanted the bytes off the bus. With DataDungeon's store in a bucket that is a presigned URL; with local storage it is http://127.0.0.1:<port>/media/<key>, since caller and service share the machine.

We fetch it rather than passing the URL through to the provider, and the localhost case is why. Runware's inputImage does accept a URL, so a public bucket link could in principle go straight through and save a round trip. A loopback URL cannot: Runware's servers have no route to the caller's 127.0.0.1. Handling only the public case would mean a parameter that works for one caller's storage backend and fails confusingly for another's, so this always fetches. The goal was to keep bytes off the BUS, which it does completely.

Pass-through for genuinely public URLs remains a possible optimisation. It saves one download and one upload per shot, and would need the transport interface to carry "bytes or URL" rather than bytes.

Where it may fetch from (the security review, 2026-10-21). Any bus participant can name the URL, so an unchecked fetch is a way into the droplet's own network: its metadata service at 169.254.169.254, or any service listening on loopback. So the host is resolved, its addresses are checked, and the connection goes to one that passed, never to a second lookup that could answer differently (DNS rebinding). Redirects are checked the same way, hop by hop. Allowed: public addresses over http or https, and loopback over http for paths under /media/, the shape of DataDungeon's local store. A failure says why without echoing what came back, since that could be an internal service's reply.

Constants

DEADLINE = 60.seconds

The whole fetch, redirects included, so a server trickling bytes can't hold it.

LOCAL_MEDIA = /\A\/media\/(?!.*\.\.)[A-Za-z0-9._~\/-]+\z/

A local store's path: under /media/, plain characters only, so neither .. nor a percent-escape can step out of it.

MAX_BYTES = (32 * 1024) * 1024

Generous for a local store, bounded so a mistyped URL pointing at something huge cannot exhaust memory: counted while reading, never after.

MAX_REDIRECTS = 2

Class methods

fetch(url : String) : Bytes
Source
public?(ip : Socket::IPAddress) : Bool

Globally routable: not private, loopback, link-local, shared (CGNAT), reserved, documentation, multicast or unspecified.

Source

Nested types