# Security model

Source: https://dropshelf.ai/docs/reference/project/security

What dropshelf defends against, the defences that carry the most weight, the risks it accepts and how to report a vulnerability.

This page describes what a dropshelf instance trusts, how it defends itself and which risks it
accepts by design. It is for operators and security reviewers. [How dropshelf works](/docs/reference/project/architecture)
describes the hosts, cookies and caches this model rests on.

## Threat model [#threat-model]

Members are trusted people of one organisation, signed in through its identity provider. Every drop
is arbitrary HTML and JavaScript that one of them wrote. Each drop is served on a sibling subdomain
of the control plane, so `<name>.drop.example.com` sits beside the dashboard at `drop.example.com`.

The model therefore guards the control plane and other members' access against any drop's code. It
does not treat a member as an anonymous attacker.

## Defences [#defences]

These defences carry the most weight, roughly in order.

### Uploads never touch a filesystem tree [#uploads-never-touch-a-filesystem-tree]

Object keys are built by the server, never taken from a zip. Nothing from an upload is written to a
directory tree, so path traversal has no target. Rules on each path segment and the refusal of
symlinks are further layers.

A zip is checked before the server answers `202 Accepted`. The server caps the compressed size, the
size of each file, the total uncompressed size and the number of entries. It refuses encrypted
entries, compression methods other than store and deflate, and paths under the reserved
`_dropshelf/` prefix. The [configuration reference](/docs/reference/configuration#deploy) has the
limits.

### The Origin check stops cross-site requests [#the-origin-check-stops-cross-site-requests]

`SameSite` cookies give no protection here. Sibling subdomains are the same site, so a `SameSite=Lax`
cookie flows from `evil.drop.example.com` to `drop.example.com`. The defence against cross-site
request forgery is the `Origin` header instead:

- Every unsafe request to the API without a bearer token must carry an `Origin` equal to the control
  plane's.
- Only when `Origin` is absent may `Sec-Fetch-Site: same-origin` stand in for it.
- A body must be JSON, a zip, JSON Lines, raw bytes or a PNG, JPEG or WebP image. Form types are
  refused with `415`.

An HTML form cannot send any of the allowed types. A page on another origin would need a preflight,
and the API sends no CORS headers, so it never grants one. A drop's own data routes accept only
requests from that drop's own origin.

### Framing is limited on both kinds of host [#framing-is-limited-on-both-kinds-of-host]

Control-plane responses carry `frame-ancestors 'none'` and `X-Frame-Options: DENY`. Drop responses
allow only the drop itself and the dashboard to frame them. That keeps one drop from framing a
restricted drop with the reader's access and laying its own page over it.

### Cookies cannot stand in for each other [#cookies-cannot-stand-in-for-each-other]

The dashboard's session cookie is `__Host-` prefixed, so no drop host can set or replace it. The
visitor cookie reaches every drop host. Both are encrypted and authenticated, with the cookie's kind
bound into the encryption. A visitor cookie can never be presented as a session cookie.

### Sessions are revocable [#sessions-are-revocable]

The admin flag is never in a cookie. Renewing a session reads the member's row again and fails
closed. The server rereads that row behind a 30-second cache on each replica.

Disabling a member, signing out or changing the admin flag takes effect at once on the replica that
made the change. It takes effect within 30 seconds on every other replica. Signing out ends every
session that holds the member's cookies, on every device.

### Names stay hidden from strangers [#names-stay-hidden-from-strangers]

Every route resolves a drop's name only after authentication. A client that is not signed in learns
nothing about which names exist. A signed-in member is still told that a name is taken, whoever
holds it and whatever its visibility, because the name is taken.

### Preview addresses carry no authority [#preview-addresses-carry-no-authority]

A preview address such as `v7--blog.drop.example.com` is guessable by design. Every request to it is
checked for the right to edit the drop, the same check the dashboard makes. The version is looked up
within that drop. Every refusal shows the same page as an address that names nothing, so nobody can
use it to learn which versions exist.

### Tokens [#tokens]

A [personal access token](/docs/use/tokens) is shown once and stored as a SHA-256 hash. It starts
with `odp_` so secret scanners recognise it. Every token expires, at most after
[`tokens.maxTTL`](/docs/reference/configuration#tokens), and its owner or an admin can revoke it.

### Text is stored and shown as text [#text-is-stored-and-shown-as-text]

Comments and bios are trimmed and stored as given. They are capped in bytes by
[`social.maxCommentBytes`](/docs/reference/configuration#social) and
[`profiles.maxBioBytes`](/docs/reference/configuration#profiles). Control characters other than a
newline, a carriage return and a tab are refused. The dashboard renders both as text, never as HTML.

### Pictures and uploaded files cannot run script [#pictures-and-uploaded-files-cannot-run-script]

A profile picture must be PNG, JPEG or WebP. The server decides the type from the bytes, not from
what the upload declared. SVG is refused because it can carry script. Pictures are served with
`nosniff` and `private` caching, so a shared cache cannot hand one member's picture to another.

Files that visitors upload to a drop, when an admin turns
[uploaded assets](/docs/self-host/configure/features) on, are served with a `sandbox` policy. An
HTML or SVG file opened from its address runs nothing as the drop.

### The container [#the-container]

The image is distroless, runs as a non-root user and has no shell. It expects a read-only root
filesystem. `govulncheck` runs in CI against the pinned Go toolchain.

## Accepted risks [#accepted-risks]

dropshelf accepts the following risks rather than mitigating them. Each says why.

### Cookie planting on drop hosts [#cookie-planting-on-drop-hosts]

A drop can set a cookie named `__Secure-dropshelf_visitor` on `.drop.example.com`. The payload is
encrypted and authenticated, so the attacker cannot forge another identity. They can plant their
own valid visitor cookie. A victim browsing other drops then appears to be the attacker.

With [drop data](/docs/self-host/configure/features) turned on, the victim's writes on drop hosts are
attributed to the attacker, who can then edit them. Nothing of the victim's is read: page script
cannot read the cookie. Likes, comments and the dashboard use the session cookie, which no drop can
plant. Every affected document carries the planter's id, which is acceptable among named colleagues.

### Script in SVG files [#script-in-svg-files]

An SVG file in a drop can contain script. It runs in the drop's own origin, the same as any HTML the
same author could upload.

### Public means every member [#public-means-every-member]

Any signed-in member can read any public drop's details and content. A drop host authenticates every
visitor before it resolves the name, so "public" means every member of the instance, never the open
internet.

An owner can make a drop restricted to the people they add, or private to themselves.
[Share a drop](/docs/use/share) covers the choices. The API answers a restricted drop as an unknown
name to anyone else. Its drop host tells them that it exists and who owns it, which the taken name
already tells them. A private drop answers as unknown on both.

### Reused names [#reused-names]

A name is free again as soon as its drop is deleted or expires, and anyone can take it at once. A
link that was passed around may then open someone else's drop. The trust model accepts this.

### Look-alike pages [#look-alike-pages]

A colleague's page at `login.drop.example.com`, behind a valid wildcard certificate, would be a
phishing surface. [`slugs.reserved`](/docs/reference/configuration#slugs) keeps back names like
that, related to signing in or to the brand. Any other name can still host a convincing page, and
the trust model accepts that.

### No embedding on other domains [#no-embedding-on-other-domains]

A page on another domain cannot frame a drop. That is the framing defence at work, and it means a
drop cannot be embedded outside dropshelf.

## Report a vulnerability [#report-a-vulnerability]

Do not open a public issue for a security problem. Report it privately as the repository's
[security policy](https://github.com/dropshelf/dropshelf/blob/main/SECURITY.md) describes. Include
what you found, how to reproduce it and the version you ran. Until 1.0, security fixes ship in the
newest minor release only.

## Related topics [#related-topics]

- [How dropshelf works](/docs/reference/project/architecture)
- [Releases and versions](/docs/reference/project/releases)
- [Production checklist](/docs/self-host/install/production-checklist)
- [Rotate secrets](/docs/self-host/operate/rotate-secrets)
- [Share a drop](/docs/use/share)
