Annotation store¶
iiiris can host W3C Web Annotations in durable storage and serve them per
the W3C Web Annotation Protocol:
each container is an LDP Basic Container of annotations, read as paged
AnnotationPages. Derived IIIF Presentation 3.0 manifests reference the
stored annotations of each canvas, so Mirador (and any viewer that follows
annotations references) shows them. The bundled Mirador can also create,
edit and delete annotations in the browser.
It is off by default (it adds durable state and a write surface). The
contract is specs/annotations.md.
Enable it¶
annotations:
enabled: true
dir: /var/lib/iiiris/annotations # durable, never evicted
write_token: "change-me" # bulk / machine writes (Bearer)
write_profile: "" # optional: browser writes via an IIIF Auth profile
Or with env vars: IIIRIS_ANNOTATIONS_ENABLED=true,
IIIRIS_ANNOTATIONS_DIR=…, IIIRIS_ANNOTATIONS_WRITE_TOKEN=…,
IIIRIS_ANNOTATIONS_WRITE_PROFILE=…. Every field (including max_bytes,
default 262144, and page_size, default 100) is in
configuration.md.
At startup iiirisd refuses to start when dir cannot be created or written
(it probes with a real write), when page_size or max_bytes is below 1, or
when write_profile names a profile that is not configured under auth:, or
one whose login does not verify its users. Browser writes need a verified
user, because it becomes each annotation's creator and owner: use an active profile on the builtin backend, or an oidc or external backend.
Other combinations are refused: the builtin backend's clickthrough pattern
accepts any posted username, kiosk uses the client IP, and the header
backend creates no session. For anonymous or bulk writes, use the write
token.
Reads follow the image's access. Annotations in an image's container
(see Containers below) are readable by anyone who may view that image,
including through a degraded substitute. A reader the image's auth rules or
hook refuse gets 401 for its annotations too. Annotations of public images,
and annotations in containers that aren't named after an image, are
readable by anyone. The write token reads everything. A browser session can
only write to an image's container if it may view the image. Writes are refused unless a credential below admits them. With
neither write_token nor write_profile set the store is read-only.
Containers and the derived manifests¶
An annotation lives in a container, a name made of A-Z a-z 0-9 _ -
(1 to 240 characters), optionally followed by ~ and a number. Containers are
created by their first write; a container nobody has written to reads as an
empty container (200), not 404.
When the store is enabled, each canvas of a derived Presentation 3.0
manifest gains an annotations reference to
/annotations/{container}/?page=0, where {container} is
base64url(image identifier) (without padding) of the image the canvas
paints, e.g. library/manuscript/f001.tif. An image identifier whose encoding
exceeds 240 characters gets no reference. Stored manifests and 2.1 manifests
are unchanged: to show annotations on a stored manifest, add the reference
yourself.
Containers are keyed by image, so adding, removing or reordering images in
a directory leaves every image's annotations on that image. Canvas ids stay
positional (…/canvas/{n}), so iiirisd serves each annotation in an image's
container with its target pointed at the canvas that currently paints that
image; viewers draw it on the right picture after the directory changes.
Renaming or moving an image file changes its identifier and so its
container: its annotations stay under the old name until you move the
container directory yourself.
For bulk ingest you can write to any valid container name; to have an
annotation appear on a derived canvas, use the container in that canvas's
annotations reference, or compute it from the image identifier:
IMG=library/manuscript/f001.tif
C=$(python3 -c 'import base64,sys; print(base64.urlsafe_b64encode(sys.argv[1].encode()).decode().rstrip("="))' "$IMG")
echo "$C"
Reading¶
curl -s http://localhost:8080/annotations/$C/ # container, first page embedded
curl -s -H 'Prefer: return=representation;include="http://www.w3.org/ns/oa#PreferContainedIRIs"' \
http://localhost:8080/annotations/$C/ # contained annotations as IRIs only
curl -s http://localhost:8080/annotations/$C/?page=1 # one AnnotationPage
The Prefer header's include parameter selects the container shape: oa#PreferContainedIRIs
(IRIs only), oa#PreferContainedDescriptions (full annotations, the default)
or ldp#PreferMinimalContainer (no page). Responses carry strong ETags
(distinct per Prefer variant) and revalidate (Cache-Control: no-cache);
there is no Last-Modified. Pages run from 0 to the container's last
page; any later page is 404 (an empty container has just page 0).
Writing with the token (bulk ingest)¶
Authorization: Bearer <write_token>. The client's creator is preserved,
which suits machine-generated annotations (OCR, HTR, tagging). The body must be
a JSON Web Annotation: @context including
http://www.w3.org/ns/anno.jsonld, type including Annotation, and a
target.
# Create. Slug is optional (a-z 0-9 -, up to 64 chars); a taken or invalid Slug
# falls back to a generated id.
curl -si -X POST http://localhost:8080/annotations/$C/ \
-H "Authorization: Bearer $TOKEN" -H 'Slug: ocr-line-1' \
-H 'Content-Type: application/ld+json; profile="http://www.w3.org/ns/anno.jsonld"' \
-d '{"@context":"http://www.w3.org/ns/anno.jsonld","type":"Annotation",
"creator":{"type":"Software","name":"my-ocr 1.2"},
"body":{"type":"TextualBody","value":"Dear Sir","format":"text/plain"},
"target":"http://localhost:8080/iiif/presentation/3/library/manuscript/canvas/1#xywh=10,10,300,40"}'
# -> 201, Location: …/annotations/<C>/ocr-line-1, ETag: "…"
# Replace and delete require If-Match with the current ETag
curl -si -X PUT http://localhost:8080/annotations/$C/ocr-line-1 -H "Authorization: Bearer $TOKEN" \
-H 'If-Match: "<etag>"' -H 'Content-Type: application/ld+json' -d @updated.json
curl -si -X DELETE http://localhost:8080/annotations/$C/ocr-line-1 -H "Authorization: Bearer $TOKEN" \
-H 'If-Match: "<etag>"'
The server assigns id, created and modified; a client-supplied id is
ignored. A missing If-Match is 428, a stale one 412, a body over max_bytes
413, a malformed annotation 400, a bad or missing credential 401. Keep the
token out of version control and shell history; it is redacted in
-print-config.
Writing from a browser (the bundled editor)¶
Set write_profile to the key of an auth.profiles entry. A valid IIIF Auth
session for that profile then authorizes browser writes, and the bundled
Mirador at /view/{id} loads the Mirador Annotation Editor: users sign in
through the profile's login service and create, edit and delete annotations
on canvases. The editor loads only when the store is on, write_profile is
set and its session store is available, and the page is /view/{id} for a
manifest on this server in Mirador (not ?viewer=uv, and not a
iiif-content link). Otherwise Mirador is plain and still displays stored
annotations.
When a save needs sign-in, the editor opens the login service in a pop-up
and saves once the pop-up reports that sign-in finished. Identity providers
that send Cross-Origin-Opener-Policy (Google and Microsoft, for example)
make the pop-up look closed while the user is still signing in. The editor
then asks the user to finish signing in and waits up to three minutes for
the pop-up's message before giving up.
Session writes are stricter than token writes:
Originmust equal the server's public origin (scheme://host[:port],X-Forwarded-*honoured) or the write is 403. The session cookie isSameSite=None; Secure, so the origin check is the CSRF defence.POST/PUTneedContent-Type: application/ld+json(415 otherwise).@contextmust be the anno context, or an array of only the anno and IIIF Presentation 3 contexts (400 otherwise).- Bodies that could let a JSON-LD processor attach a client-chosen creator to
a stored annotation are refused (400):
@nest,@graph,@reverseor@includedanywhere;@contextbelow the top level; and a nested node carrying acreatorwhoseidis relative or points into/annotations/. Ordinary bodies, including Mirador Annotation Editor's tags and acreatoron an external or blank body node, are unaffected. - Any top-level client-supplied
creator(includingdcterms:creatorand its full IRI) is removed. A profile that names its users records the session user as{"type":"Person","name":…}. The guarantee is on the top-levelcreatorof the stored JSON; the server does not run a JSON-LD processor (see the spec). - An
Authorizationheader, if sent, is the only credential considered.
Only an annotation's creator may change it from a browser. A session
PUT or DELETE is refused with 403 unless the session user created the
annotation from a browser. The server records that owner beside the
annotation ({id}.owner in the store directory); the annotation's creator
plays no part. Annotations ingested with the token can't be changed from a
browser, even when their creator names a user. The write token may change
any annotation. There are no administrator or group roles: use the token for
moderation. See iiif-auth.md for profiles.
Operator notes¶
- While the store is on, every viewer page sends a script
Content-Security-Policy, because annotation bodies are user-written HTML and any viewer may render them: Mirador pages getscript-src 'self' 'nonce-…'; object-src 'none'; base-uri 'none', the Universal Viewer pagescript-src 'none'; …, and the UV shim (/static/viewer/uv.html) allows only this server, UV's pinned CDN release and its own bootstrap by hash. Editable/view/{id}pages addframe-ancestors 'self'andX-Frame-Options: SAMEORIGIN; do not embed those from another origin. Read-only viewer pages stay embeddable. With the store off, none of these headers is sent. - The editor adapter fails closed on concurrent edits: if an annotation changed since the page loaded, the save is refused and the user must reload.
- The bundled Mirador is the 4.x line, which with the editor makes the embedded bundle about 2.9 MB for every deployment, annotations or not.
Storage, backup and scaling¶
Annotations are files: each container is a directory under dir named by a
hash of the container name, holding {id}.json per annotation, .index
(ordered ids), .rev (the container revision that drives page ETags) and
.name (the container name, for finding a container on disk). Hashed names
keep containers whose names differ only in case apart on case-insensitive
filesystems (the macOS and Windows defaults). A store written by an earlier
build, with directories named by container, is moved to hashed names at
startup.
Use a different dir from content_state.store.dir. Backup is copying
dir (stop writes or snapshot the volume for a consistent copy). The store
is single-node: do not share one dir between replicas.
Conformance and CI¶
tools/iiif-annotation-conformance is a project-local harness that checks the
protocol's headers and shapes against a live server; CI runs it as
iiif-annotation-validate. The viewer end-to-end test drives the editor.
go build -o /tmp/iiif-annotation-conformance ./tools/iiif-annotation-conformance
/tmp/iiif-annotation-conformance -base http://localhost:8080 -token "$TOKEN"
Not yet shipped¶
- Administrator or group roles for browser edits.
- Search beyond a single manifest (see Content Search).
- Multi-replica storage backends.
- The editor in Universal Viewer.
See also¶
specs/annotations.mdfor the contract.presentation.mdandiiif-auth.md.