Documentation
¶
Overview ¶
Package mediafetch downloads scraped image assets with SSRF and size guards, and detects signed URLs whose expiry has already passed.
Index ¶
Constants ¶
const MaxBytes = 10 * 1024 * 1024
MaxBytes caps how much of a response is read, so a hostile or misconfigured host cannot exhaust memory.
Variables ¶
This section is empty.
Functions ¶
func DataURI ¶ added in v1.30.0
func DataURI(ctx context.Context, client *http.Client, rawURL string, allowPrivate bool) (string, error)
DataURI fetches an image and encodes it as a data URI, the form Stash's cover_image field takes.
A URL carrying an already-passed signed expiry is rejected without a request: scraped CDN thumbnails are often dead within hours of the scrape.
func Expired ¶
Expired reports whether rawURL carries a signed expiry that has already passed at time now.
Many CDNs hand out short-lived signed URLs — `?expires=…&token=…` — so a stored thumbnail is often dead within hours. Detecting that offline lets a caller skip a request it knows will 403, and lets the NFO writer omit a `<thumb>` rather than bake in a broken link.
It is deliberately conservative: an unrecognised or unparseable expiry returns false. A false negative costs one failed request; a false positive would discard a working URL.
func ValidateURL ¶
ValidateURL enforces the SSRF defense: http(s) only, and unless allowPrivate is set, no host that resolves to a private or loopback address.
This resolves DNS once, before the request, so DNS rebinding is not mitigated. For the threat model here — consuming someone else's scraped JSON — the dump author would also need to control DNS for a domain the importer resolves.