Skip to content
internetionalsPublic

About

Simple secure file transfer

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Koffer logo: a cream attaché case with a brass clasp on a green tile

Koffer

Secure, open-source file lockers. Koffer is Dutch for a case or coffer.

Rain on the station roof. You slide a case into a locker, turn the key and walk away without looking back. All the other party gets is a code. Hours later they key it in, prove they're the one it was meant for, and leave with the case. You never meet. When the time is up, the locker is emptied.

Koffer is that locker, for files. Put files in a locker and send its code to the people who should collect them, or leave an empty locker for someone outside your organization to fill. You decide how long the locker stays open, how often each file can be taken out and when everything is destroyed. If the contents are truly secret, encrypt them in your browser so that not even the station master can look inside.

Koffer is a single static Rust binary that serves a dependency-free single page web app for exchanging files with external parties:

  • Shares: an authorized user sends files to an external email address.
  • Requests (invites): an authorized user invites an external email address to upload files to them.

Each share or request is a locker holding any number of files that share the same access rules. A locker is opened with an unguessable locker code that is easy to type on a phone, for example K7QM-4XTR-9PDA-HW3N: 80 bits of randomness in Crockford base32, case-insensitive, with dashes optional and O/0 and I/L/1 treated as equal.

Features

  • Passwordless login for authorized users (email OTP), restricted by address/domain patterns. The session lifetime is configurable (default 1h).
  • A locker can have several recipients (external parties, max. 20 by default). Each one is emailed separately, verifies their own address and has their own download allowance. Recipients can be added and removed later; removal ends their access immediately.
  • External parties open a locker with its code and then verify their email address with an OTP. The owner can turn this off for a locker (advanced option "Require email verification", on by default): anyone with the code then gets in straight away, and they all share one download allowance per file. Changing the locker's settings still requires the owner's login. Admins can forbid turning it off, or turn verification off for every locker.
  • Every locker limits how often each recipient may download each file, so the service can't be used for mass distribution. Owner downloads are not counted.
  • Shares have downloads per file, an access period and a retention date. Access can be re-enabled later: raise the download count, extend the access period, or extend retention up to the hard limit. Optionally, recipients may upload files back into the same locker (collaboration). They can then delete or replace only their own uploads, their uploads have a quota and maximum number of files, and the owner is notified.
  • Requests have downloads per file, a quota and an access period, plus an optional maximum number of files. Optional settings: the uploader may download, delete or replace their files; the notification target (default: the owner); allowed extensions; a filename regex.
  • Global policies that cannot be bypassed: an extension allowlist, a filename regex, the maximum retention and access period, allowed recipients and allowed notification targets.
  • Optional end-to-end encryption (AES-256-GCM in the browser). The key is delivered in the email link (simple) or by the owner out-of-band (most secure). Before a key is emailed, each recipient's domain is checked for DANE (DNSSEC-validated MX records, plus TLSA records on every MX host). If a domain doesn't have it and isn't configured as secure, the owner is warned (listing the recipients concerned) and must explicitly confirm before the key is sent. Either way, the sender is shown the key right after creating the locker. They can copy it, copy a link containing it, or download a key file for their own records, and it stays available under "Show key" (for example to send a new link if the recipient loses theirs).
  • Chunked uploads (sized for proxy/CDN body limits) with a SHA-256 per chunk and for the whole file, both verified by the server. Checksums are stored and shown. Downloads stream through a service worker straight to disk: decrypted on the fly for E2E files, and SHA-256 verified while streaming, without buffering the file in memory.
  • Upload validation hook (e.g. a virus scanner). Files that are not yet validated, or that failed validation, can only be downloaded through an explicit warning and get a .unsafe suffix. E2E files show a banner saying they were not validated.
  • Encryption at rest of the SQLite database (SQLCipher) and of all blobs, derived from one master key file.
  • Batched upload notifications, automatic cleanup and an audit log (in the database and in the log output).
  • English, Dutch, German, French, Spanish and Italian UI and emails. Email templates (HTML and text) and translations can be exported and overridden.
  • Basic theming: a custom logo and a custom stylesheet.
  • Strict security headers: a CSP that allows 'self' only, with Trusted Types enforced (the UI never uses innerHTML), COOP/COEP/CORP, no-referrer, noindex, frame denial and HSTS. The only Trusted Types policy (koffer-sw) accepts exactly two script URLs: /sw.js and /static/crypto.js.

Quick start (local)

cargo build --release
./target/release/koffer generate-key > master.key
KOFFER_DATA_DIR=./data KOFFER_MASTER_KEY_FILE=./master.key \
KOFFER_ALLOWED_USERS='*@example.com' KOFFER_COOKIE_SECURE=false KOFFER_HSTS=false \
./target/release/koffer

Open http://localhost:8080. Without KOFFER_SMTP_HOST, emails (including OTP codes) are written to the log. This is for development only: in this mode the log also contains share links, including E2E keys that are delivered by email.

Containers

Containerfile produces a FROM scratch image (non-root UID 65532, read-only root filesystem compatible) whose only writable path is /data.

podman build -t localhost/koffer:latest -f Containerfile .
mkdir -p secrets && podman run --rm localhost/koffer generate-key > secrets/master.key
KOFFER_ALLOWED_USERS='*@example.com' SMTP_SENDER_DOMAINS=example.com docker compose up -d

compose.yaml runs three services:

service networks purpose
proxy (Caddy) frontend, backend public entry point; set SITE_ADDRESS=files.example.com for automatic HTTPS
koffer backend only (internal: true) cannot reach anything except the SMTP relay
smtp (boky/postfix) backend, egress relays mail with DANE (smtp_tls_security_level=dane); set SMTP_RELAYHOST etc. for complex mail setups
resolver (Unbound) backend, egress DNSSEC-validating resolver for the DANE check in Koffer and for Postfix; read-only, except the resolver-data volume where it keeps the DNSSEC root trust anchor up to date

The backend network uses the fixed subnet 10.253.53.0/24, because Postfix needs the resolver's IP address. If that collides with something on your host, or you run two stacks, set KOFFER_BACKEND_SUBNET and KOFFER_RESOLVER_IP.

For acceptance, Mailpit replaces the relay and no mail leaves the environment. Its UI is at http://localhost:8025.

docker compose -f compose.yaml -f compose.acceptance.yaml up -d

Behind HTTPS, set KOFFER_COOKIE_SECURE=true and KOFFER_HSTS=true, and set KOFFER_BASE_URL to the public URL.

deploy/k8s/koffer.yaml is a Kubernetes example. It includes a restricted securityContext, a PVC for /data, the master key mounted from a Secret, and a NetworkPolicy that allows ingress only from the ingress controller and egress only to the SMTP relay and DNS. Run one replica: SQLite has a single writer, and rate limits are kept in memory.

Configuration

Every option is a command line flag with an environment variable fallback. See koffer --help for the full list with defaults. Secrets are never accepted directly, only as a path to a file (a container or Kubernetes secret mount).

Variable Default Meaning
KOFFER_LISTEN 0.0.0.0:8080 listen address
KOFFER_DATA_DIR /data the only writable path: koffer.db, blobs/, tmp/
KOFFER_BASE_URL http://localhost:8080 public URL used in emails
KOFFER_SITE_NAME Koffer name in the UI and emails
KOFFER_MASTER_KEY_FILE – master secret file for encryption at rest (koffer generate-key)
KOFFER_ALLOWED_USERS – patterns of addresses that may log in: *@example.com,alice@partner.org (*, ?; a bare domain means *@domain)
KOFFER_ALLOWED_RECIPIENTS * who files may be shared with or requested from
KOFFER_ALLOWED_NOTIFY_TARGETS * allowed upload notification targets
KOFFER_SESSION_LIFETIME / KOFFER_OTP_LIFETIME 1h / 10m login session and OTP lifetime
KOFFER_REQUIRE_RECIPIENT_VERIFICATION true external parties must verify their email after entering the code. When off, no locker asks for it: everyone with the code shares one anonymous identity and one download allowance
KOFFER_ALLOW_UNVERIFIED_LOCKERS true owners may turn off email verification for a locker of theirs (with the same effect, for that locker only)
KOFFER_RETENTION_DEFAULT / _MAX 7d / 30d default and hard limit for automatic file cleanup
KOFFER_ACCESS_DEFAULT / _MAX 7d / 30d default and maximum external access period
KOFFER_INVITE_DEFAULT_MAX_FILES / KOFFER_INVITE_MAX_MAX_FILES 10 / 1000 files per request (advanced option)
KOFFER_INVITE_DEFAULT_QUOTA / KOFFER_INVITE_MAX_QUOTA 1G / 20G quota per request
KOFFER_DOWNLOADS_DEFAULT / KOFFER_DOWNLOADS_MAX 5 / 100 downloads per file per recipient (shares and requests)
KOFFER_MAX_RECIPIENTS 20 maximum number of recipients per locker
KOFFER_MAX_FILE_SIZE 20G maximum size of one file
KOFFER_CHUNK_SIZE 8M upload chunk size; keep it below proxy/CDN body limits
KOFFER_ALLOWED_EXTENSIONS_DEFAULT / _GLOBAL * / * default per locker, and a global allowlist that can't be bypassed (pdf,docx,tar.gz)
KOFFER_FILENAME_REGEX_DEFAULT / _GLOBAL empty default per locker, and a global regex every filename must match
KOFFER_E2E_DEFAULT false E2E pre-selected in the forms
KOFFER_VALIDATE_COMMAND – validation hook (see below)
KOFFER_VALIDATE_TIMEOUT / _CONCURRENCY 10m / 2
KOFFER_SMTP_HOST / _PORT – smarthost
KOFFER_SMTP_TLS starttls none, starttls or tls (implicit)
KOFFER_SMTP_USERNAME / KOFFER_SMTP_PASSWORD_FILE – optional SMTP authentication
KOFFER_SMTP_FROM Koffer <noreply@localhost> sender
KOFFER_DNS_RESOLVER first nameserver in /etc/resolv.conf DNSSEC-validating resolver (ip:port or host:port) for the DANE check; its AD flag is trusted
KOFFER_SECURE_ALLOWED_USER_DOMAINS false treat addresses matching KOFFER_ALLOWED_USERS (your own, often internal, mail) as secure for key emails
KOFFER_SECURE_MAIL_DOMAINS empty further domains/wildcards treated as secure without DANE, e.g. partner.org,*.gov.example
KOFFER_TEMPLATE_DIR – custom templates/translations (see below)
KOFFER_THEME_DIR – logo.svg/logo.png/logo.webp/logo.jpg and custom.css
KOFFER_DEFAULT_LANG en fallback language
KOFFER_COOKIE_SECURE / KOFFER_HSTS true / true disable only for plain-http development
KOFFER_TRUST_PROXY false use the right-most X-Forwarded-For entry as the client IP (rate limiting, audit)
KOFFER_CLEANUP_INTERVAL, KOFFER_STALE_UPLOAD_AGE, KOFFER_NOTIFY_DELAY 1m, 24h, 2m background jobs
KOFFER_LOG / KOFFER_LOG_FORMAT info / text log filter; json for log collectors

Templates and translations

koffer export-templates ./custom     # writes custom/templates/*.html|txt and custom/i18n/*.json
KOFFER_TEMPLATE_DIR=./custom koffer
  • Templates use MiniJinja and call t("key", name=value) for translated strings. A language specific variant such as share.nl.html takes precedence over share.html.
  • Translation files are merged over the built-in ones. Missing keys fall back to English, so you only need the keys you change. Adding i18n/fr.json adds a language to the UI and emails. Strings use {name} placeholders.
  • Email subjects are the translation keys email.<template>.subject.

Theming

Put logo.svg (or .png, .webp, .jpg) and/or custom.css in KOFFER_THEME_DIR. Most colours are CSS variables, so a small override is usually enough:

:root { --primary: #0b7a3e; }

Upload validation

KOFFER_VALIDATE_COMMAND is split shell-style (no shell is involved). It runs with two extra arguments: the path of the plaintext blob and the original filename. Exit code 0 means clean, 1 means rejected, and anything else (or a timeout) is a validation error. The output, truncated to 4 KiB, is stored and shown to the owner.

Validation runs on a temporary plaintext copy in /data/tmp, which is removed afterwards. The stored blob is encrypted as soon as the upload completes. Pending validations resume after a restart.

Downloads by status:

status download
passed, or no validator configured normal
pending / running / error explicit confirmation; saved as name.unsafe
failed owner only, with explicit confirmation, as name.unsafe
E2E normal, with a banner that the service could not validate the files

deploy/validator/ has an example image with a ClamAV (clamdscan --stream) hook.

Security design

Authentication. OTPs are 8 digits, valid for 10 minutes, and limited to 5 attempts. Only the newest code is valid, and they are stored as HMAC values. Requests are rate limited per IP and per address. The responses never reveal whether an address is allowed. Session tokens are 256-bit random values stored as HMACs, in an HttpOnly, SameSite=Strict, __Host- cookie. Every state-changing request must carry the X-Koffer: 1 header and pass the Sec-Fetch-Site checks (CSRF protection). The allowlist is checked on every request, so after a restart with a narrower KOFFER_ALLOWED_USERS, the existing sessions of users who no longer match stop working.

External access. A locker opens only with its code (rate limited) and, by default, an OTP sent to one of its recipient addresses (the visitor enters their address; responses don't reveal whether it is a recipient). Recipients don't see each other's addresses, except as uploader names in a locker that allows recipient uploads. For requests, the configured notification target can also verify itself to view and download. Revoking access, removing a recipient, or letting the access period expire ends the guest sessions concerned.

Ownership of files. Only the owner may delete or replace files someone else uploaded. Recipients (where allowed) can only touch their own uploads.

Downloads. Downloads use short-lived (6h) single-file tickets. The download limit applies per recipient and file (shares and requests; the owner is exempt) and is counted when the ticket is issued. Responses are always attachment, application/octet-stream, with a sandbox CSP, and include the SHA-256 checksum (Repr-Digest / X-Checksum-SHA256). Range requests are supported.

Encryption at rest. HKDF on the master key derives a SQLCipher key and a blob key. Each blob gets its own key (HKDF with the blob UUID). Blobs are encrypted with AES-256-GCM in 64 KiB segments. The segment index and a final-segment flag are authenticated, so truncation or reordering is detected, and random access still works. The service refuses to start with the wrong key. Configure the key before first start: converting an existing unencrypted database, and rotating the master key, are not implemented.

End-to-end encryption.

  • The browser generates a 256-bit key and the server stores only an HMAC-derived key check value.

  • Each file gets a random salt. HKDF derives the file key, and every upload chunk is a separate AES-GCM segment whose nonce and AAD bind the chunk index and the last-chunk flag.

  • The plaintext SHA-256 travels in encrypted metadata, so the downloader verifies the decrypted file. The server verifies the checksum of the ciphertext.

  • The sender gets the key at creation, with copy and key-file options, and can always reveal it again on the locker page. Losing it means losing access to the files: the server cannot recover it.

  • Keys reach the browser through the URL fragment (/c/CODE#k=…), which is never sent to the server and is removed from the address bar after loading. They are kept in localStorage, with a "forget key" button.

  • With the simple key in email option, the server handles the key briefly to compose the email. It is never stored, but it does pass through the server and the mail system. Sending it is acceptable when the email travels over authenticated TLS. Koffer therefore checks the recipient domain before emailing a key:

    • DANE: MX records validated by DNSSEC, and DNSSEC-validated TLSA records (_25._tcp.<mx>) on every MX host.
    • Trusted: the address matches KOFFER_SECURE_MAIL_DOMAINS, or KOFFER_ALLOWED_USERS when KOFFER_SECURE_ALLOWED_USER_DOMAINS=true.
    • Not verified: anything else, including failed lookups. The form shows a warning with the reason as soon as the recipient is entered. Sending requires an explicit confirmation, which the server enforces (HTTP 409 insecure_key_delivery without it). Each key email is audit-logged as key_email or key_email_insecure_acknowledged, with the verdict and MX hosts.

    The check reports what the recipient supports. Delivery is only protected if the mail server that sends it enforces DANE; the bundled Postfix relay does. If you use a smarthost (SMTP_RELAYHOST), make sure it does too. The hop from Koffer to the relay is internal (KOFFER_SMTP_TLS=none in compose). Use starttls or tls when the relay is elsewhere. Results are cached for an hour (5 minutes for failed lookups).

  • Filenames are not end-to-end encrypted, because the server needs them to enforce extension and regex policy.

Known limitations and choices

  • Retention can be extended up to the hard limit measured from the time of the change. This lets an owner deliberately re-enable an old share; unattended data still expires.
  • Downloads go through a service worker (web/sw.js). It holds back the final piece until the SHA-256 matches, so a corrupted or tampered file never completes: the browser marks the download as failed. In browsers without service workers (some private browsing modes), downloads up to 1 GiB fall back to in-memory buffering. Larger plain files then download directly, with the checksum shown for manual verification. Larger E2E files are refused with an explanation in that case.
  • Single instance only (SQLite, in-memory rate limiting).

Development

cargo test                     # unit tests (crypto, blob format, policies, ranges)
python3 tests/smoke.py         # end-to-end API test against the real binary (stdlib only)
python3 tests/browser.py       # UI test in headless Firefox (WebDriver BiDi): E2E crypto, service worker
                               # downloads to disk, tamper detection

Layout: src/ (backend), web/ (SPA, embedded with include_str!), assets/ (email templates and translations, embedded), deploy/ (proxy, Kubernetes, validator examples), ci/ (build, test and publish scripts used by the workflows in .forgejo/workflows/).

Images and releases

CI builds the image on every push to main and every pull request, tests the binary in it (ci/check.sh, then ci/build-image.sh and ci/test-binary.sh, which also run locally) and publishes it to the container registry at code.i10s.nl/internetionals/koffer:

Source Image tag
branch main branch-main
pull request #12 pr-12 (removed when the pull request is closed)
release tag v1.2.3 v1.2.3, and latest for the highest non-pre-release

Other branches are built through their pull request. To build one without a pull request, start CI by hand on that branch (Actions → CI → Run workflow): that publishes branch-<branch>, which is removed again when the branch is deleted.

To release: Actions → Release → Run workflow. It raises the patch version by default (or minor, major, or an exact version such as 1.2.0-rc.1), sets it in Cargo.toml and Cargo.lock, runs the checks, commits and tags v<version> on main, and creates the release in Forgejo with the commits since the previous one. The tag then builds and publishes the image. Don't create releases or tags by hand: a tag that doesn't match Cargo.toml fails the build, so the git tag, the image tag and koffer --version always agree.

Every Monday a workflow updates Cargo.lock, runs all tests and, when they pass, opens or refreshes the pull request from deps/update. Updates that need a change in Cargo.toml are listed there.

License

Copyright 2026 The Koffer Authors. Licensed under the Apache License, Version 2.0. See NOTICE for third-party attributions.

About

Simple secure file transfer

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages