Skip to content

About

a privacy-first secret note service

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

secred.link

Secure, expiring secret sharing: you write content (Markdown or rich text), optionally attach a file and protect it with a passphrase, then share a link. The server never sees plaintext. Encryption runs in the browser; the Cloudflare Worker stores only ciphertext, verification blobs, hashed keys, and TTL metadata.


Features

  • Client-side encryption — Text-only secrets use v3.j. (PBKDF2 + AES-GCM). Secrets with a file attachment use v4.j. / v4.f.: one PBKDF2 pass, then HKDF-derived subkeys for the test string, body JSON, and file. Older links may still use v3+v3 (two PBKDF2) or legacy CryptoJS (decrypt-only).
  • Password-protected secrets — Offline guessing cost is dominated by PBKDF2 iterations; users should pick strong passphrases (the UI shows rough strength hints).
  • Optional burn-after-read — Supported for text-only flows; attachments use a separate burn-token window where configured.
  • Manage link — After creating a secret, owners get a manage URL (stored briefly in localStorage) to copy the viewer link or delete the secret server-side.
  • i18n — English and Russian (apps/frontend/src/locales).

Architecture

Browser (React/Vite)
    │  HTTPS
    ▼
Cloudflare Worker (apps/backend)
    ├── Static assets ─ apps/frontend/dist (SPA)
    └── /api/*        → HTTP handler → Durable Objects
                            ├── SECRETS → SQLite-backed SecretObject (+ R2 attachment refs)
                            └── METRICS → MetricsObject (counters)

Shared logic (packages/shared) includes:

  • Cryptographic primitives and legacy compatibility
  • Zod request validation
  • API route paths, URL builders, and stable error strings
  • Types for requests/responses and stored rows

Monorepo layout

apps/frontend     React SPA (Vite, Tailwind, shadcn-style UI)
apps/backend      Worker entrypoint + Durable Objects + api/handler.ts
packages/shared   Types, crypto, validation, routes, api-errors
tests             Bun unit tests
wrangler.jsonc    Workers config (assets, DOs, R2, env vars)

Prerequisites

  • Node.js 22.22.2+ on 22.x, 24.15.0+ on 24.x, or 26+ for the development tools.
  • Bun (package manager and test runner)
  • Wrangler (installed via project devDependencies; use bunx wrangler or npx wrangler if needed)

Development

Install dependencies:

bun install

Run the full stack locally (builds the frontend, then starts the Worker with the development env from wrangler.jsonc):

bun run dev

Useful scripts:

Script Purpose
bun run build Production build of the frontend + TypeScript check all packages
bun run build:frontend Vite build only (apps/frontend/dist)
bun run typecheck tsc --noEmit for shared, backend, frontend
bun run test Bun tests in tests/
bun run lint Biome check
bun run format Biome format write
bun run cf:typegen Regenerate apps/backend/src/worker-configuration.d.ts after Wrangler binding changes

Preview with local persistence behavior:

bun run preview

HTTP API (Worker)

All JSON routes live under /api. The frontend uses helpers from packages/shared (apiUrl, etc.) so paths stay consistent with apps/backend/src/api/handler.ts.

Method Path Notes
GET /api/health Liveness + version info
POST /api/secrets Create secret; body includes ciphertext, testCiphertext, hashed keys
GET /api/secrets/:accessKeyHash Fetch ciphertext bundle (64-char hex id)
DELETE /api/secrets/:accessKeyHash/:manageKeyHash Owner delete
PUT /api/secrets/:accessKeyHash/attachment Upload encrypted attachment (X-Upload-Token)
GET /api/secrets/:accessKeyHash/attachment Download (optional burnToken query)
GET /api/metrics Disabled until METRICS_TOKEN is set; then requires Authorization: Bearer …
POST /api/metrics Same auth as GET; body JSON sets absolute counter values (merge). Example: {"created":1000,"requested":5000}. Omitted keys are left unchanged.

Plaintext never appears in these payloads.

Rate limiting (/api/*)

The Worker uses Cloudflare’s Rate Limiting binding before the HTTP API handler. Limits are applied per client IP (CF-Connecting-IP, then X-Forwarded-For, else a shared unknown bucket in dev).

Default policy (see ratelimits in wrangler.jsonc): 120 requests per 60 seconds per IP per namespace. Excess traffic receives 429 with JSON { "error": "Too many requests" } and a Retry-After header (60 seconds). Static assets are not rate limited. If wrangler deploy errors on the ratelimit binding, confirm your Cloudflare account supports Workers Rate Limiting.

Production and development env each declare their own ratelimits block (Wrangler does not inherit this section). Adjust simple.limit / simple.period (allowed periods are 10 or 60 seconds) and keep API_RATE_LIMIT_PERIOD_SEC in apps/backend/src/rate-limit.ts aligned with period for Retry-After.


Cloudflare configuration

wrangler.jsonc defines:

  • Worker entry: apps/backend/src/index.ts
  • Static assets directory: apps/frontend/dist
  • R2 bucket binding for attachments
  • Durable Object namespaces SECRETS and METRICS
  • ratelimits binding API_RATE_LIMITER for /api/* (see above)
  • Non-secret vars (APP_URL, ENVIRONMENT, VERSION_PREFIX, …)

Secrets (Wrangler)

# Optional: metrics endpoint bearer token
wrangler secret put METRICS_TOKEN

# Optional: authenticated migration/import endpoint
wrangler secret put MIGRATION_TOKEN

For local development you can put the same keys in a .dev.vars file (not committed).

Seeding historical metrics (e.g. after moving from a previous stack), with METRICS_TOKEN in place:

curl -sS -X POST "https://secred.link/api/metrics" \
  -H "Authorization: Bearer $METRICS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"created":12345,"requested":67890}'

Use non-negative integers; allowed keys: created, requested, burned, deleted, expired, migration_imported. Then GET /api/metrics to verify.

Deploy

bun run build
wrangler deploy

(bun run deploy runs a frontend build then wrangler deploy with the default environment.)

Pull request previews

Cloudflare Workers Builds runs bun run test && bun run build from the repository root. The build includes the frontend bundle and typechecking for all workspaces. Pushes to master use bun x wrangler deploy. Pushes to other branches in the connected repository use bun x wrangler preview. Look for the Workers Builds: secred-link check and the preview URL on the pull request.

The previews block in wrangler.jsonc supplies the preview bindings. Each branch gets fresh SQLite-backed SECRETS and METRICS Durable Object storage on its first deployment and keeps that storage across subsequent deployments. Static assets come from the branch build. There is no D1 binding. For incompatible schema changes, use the branch's own test data in its isolated Durable Objects. If a change introduces D1, give that branch a separate test database and apply its migrations there before deploying the preview.

PRs share the secred-attachments-preview R2 bucket and rate-limit namespace 1003, both separate from production. Use synthetic data. If a change needs to rewrite shared attachment data, provision a branch-specific test bucket and change previews.r2_buckets on that branch.

Previews use a dedicated Workers Builds deployment token. Cloudflare's Workers Scripts permission is account-scoped for this user token, so preview builds are for trusted branches in this repository. Leave the preview build variables and secrets empty. The preview runtime omits METRICS_TOKEN and MIGRATION_TOKEN, so authenticated metrics access, metrics seeding, and legacy imports are disabled by default. To exercise those endpoints, set a test-only secret on the individual preview with bun x wrangler preview secret put <NAME> --name <branch>. Production custom-domain rules are outside the scope of the preview URL.

To smoke-test a preview, check that /api/health returns environment: "preview". Open the preview homepage, then create a synthetic secret with a small attachment, open the share link, download the file, and delete the secret using its manage link. The app uses the current origin and the shared encryption constant, so the preview does not need the APP_URL or TEST_STRING runtime variables.

Self-hosting

To run your own Worker on Cloudflare (separate account, buckets, and rate-limit namespace), follow SELF_HOSTING.md. Before deploy, run bun run selfhost:check to catch common wrangler.jsonc mistakes.


Security model (short)

  • Viewer links carry the raw access key in the URL fragment; anyone with the link can request ciphertext from the API. Passphrase-protected secrets depend on password strength for confidentiality.
  • The Worker stores double-hashed access/manage identifiers; it cannot derive raw keys from stored rows.
  • Additional hardening: dashboard WAF / bot rules on your hostname, dependency updates, and CSP in apps/frontend/index.html.

Contributing

Issues and pull requests are welcome on GitHub. For larger changes, open an issue first so we can align on approach.

AI / editor assistants

Repository-specific hints for tools and agents live in AGENTS.md (layout, commands, conventions).

License

Released under the MIT License. You may run, modify, and self-host your own deployment; see SELF_HOSTING.md for Cloudflare setup.

About

a privacy-first secret note service

Resources

Stars

0 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages