Skip to main content

Module contexts

Module contexts 

Source
Expand description

JSON-LD contexts ojak does not ship, fetched to check a Linked Data Signature as Mastodon checks one.

An RsaSignature2017 signs the RDF a document means, and what it means depends on every context it names. Mastodon turns a signed activity into RDF with the contexts it preloads and fetches any other (JsonLdHelper#load_jsonld_context): a GET asking for application/ld+json, taken only when it answers 200 with that type, read up to a megabyte, and kept in its cache for 30 days. fetch makes that request, fetch_cached keeps what it got in a KvStore, and resolve finds what a document is missing and adds it to a Registry.

Nothing here runs unless an application asks: reading a document never fetches a context (see ojak-jsonld’s contexts/README.md for why), and the inbox fetches only to check the signature on an activity it has to take on one, when the application has given it a loader (Builder::remote_contexts). The fetch is the request-forgery surface that boundary exists to avoid, so it is bounded on every side: the guarded client refuses private addresses unless the application allows them and follows at most its configured redirects, a context is at most MAX_CONTEXT_BYTES, and a document may cause at most Limits::max_remote fetches within Limits::timeout in all.

Structs§

Limits
Bounds on what one document may cause to be fetched.

Enums§

Error
Why a context could not be loaded, or a document’s contexts resolved.

Constants§

CACHE_TTL
How long a fetched context is kept: Mastodon’s expires_in: 30.days.
MAX_CONTEXT_BYTES
The largest context taken: Request#body_with_limit’s default.
MEDIA_TYPE
What a context is asked for as, and the only type it is taken as.

Functions§

fetch
Fetch the context iri names, as JsonLdHelper#load_jsonld_context requests one: a GET asking for MEDIA_TYPE, taken only when it answers 200 with that type, its body at most MAX_CONTEXT_BYTES and at most the client’s own limit. What comes back is the body, which Mastodon keeps as it came.
fetch_cached
fetch, kept in kv for ttl (Mastodon keeps it for CACHE_TTL) under ["jsonld", "context", iri], as Rails.cache keeps it under jsonld:context:<iri>. Only a context that was taken is kept.
resolve
registry with every context document names that it does not hold, each loaded with load (the body fetch would return): what a Linked Data Signature on document has to be checked over. None when registry already holds every one, so a caller keeps using the registry, and any cache, it already has.