Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .dev.vars.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ SENTRY_DSN=
# proxies to it. Leave blank to skip the proxy.
BLOG_ORIGIN_URL=http://localhost:3000

# Cap proof-of-work (#98). In production this is `openssl rand -hex 32`; the
# fixed value here is deliberate, so the real challenge/solve/redeem loop runs
# instead of the disabled path. Note .dev.vars.playwright sets its own: that
# is the file the browser suite reads, and a value only here would leave every
# e2e signup on the disabled path. The disabled path has its own worker test,
# which needs no browser to prove it.
CAP_SECRET=dev-only-cap-secret-not-a-real-one-0000000000000000
# Cloudflare Turnstile (#304). These are Cloudflare's published test keys
# (always pass), so the real widget and verify loop run locally with no
# account. In production, create a widget in the Cloudflare dashboard and set
# both as secrets (prod.secrets.env.example). Leave both blank to turn the
# check off.
TURNSTILE_SITE_KEY=1x00000000000000000000AA
TURNSTILE_SECRET_KEY=1x0000000000000000000000000000000AA

# Google Web Risk (#341): a second check on every destination, on create, on
# edit and weekly for free links. Leave blank locally: the Cloudflare DNS check
Expand Down
12 changes: 7 additions & 5 deletions .dev.vars.playwright
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ CF_ZONE_ID=
# staged DNS/TLS delays local dev shows off are only a timer to race.
CF_DEV_ENV=instant

# Cap proof-of-work (#98). Set here, not just in .dev.vars, because this is
# the file the browser suite actually reads: CLOUDFLARE_ENV=playwright makes
# wrangler prefer it, so a secret only in .dev.vars leaves every e2e signup
# running the disabled path while looking like it covers the real one.
CAP_SECRET=playwright-only-cap-secret-32-chars-min
# Cloudflare Turnstile (#304), with Cloudflare's always-pass test keys. Set
# here, not just in .dev.vars, because this is the file the browser suite
# actually reads: CLOUDFLARE_ENV=playwright makes wrangler prefer it, so keys
# only in .dev.vars leave every e2e signup running the disabled path while
# looking like it covers the real one.
TURNSTILE_SITE_KEY=1x00000000000000000000AA
TURNSTILE_SECRET_KEY=1x0000000000000000000000000000000AA

# Google sign-in. The local emulate google service, started by the resend
# webServer in playwright.config.ts (resend on 4000, google on 4001).
Expand Down
2 changes: 1 addition & 1 deletion .dev.vars.self-host
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The worker environment for `bun run e2e:self-host` (playwright.self-host.config.ts).
#
# A fork as it first comes up: no email provider, no Polar, no Google
# sign-in, no Cap. Each of those is a mode the app has to handle on its own
# sign-in, no Turnstile. Each of those is a mode the app has to handle on its own
# (sign-up without a code, no billing, the admin warning), and this is the
# only place a browser sees them. The config copies this file over the
# .dev.vars the build emitted, so a developer's own .dev.vars never decides
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
key: node_modules-${{ runner.os }}-${{ hashFiles('bun.lock') }}
- name: Install dependencies
run: bun install --frozen-lockfile
# Worker tests read secrets (BETTER_AUTH_SECRET, CAP_SECRET, ...) out of
# Worker tests read secrets (BETTER_AUTH_SECRET, TURNSTILE_SECRET_KEY, ...) out of
# the ambient miniflare env, which wrangler builds from .dev.vars. Without
# it those bindings are empty, so auth/rate-limit code 500s instead of
# behaving: same reason the old single-job workflow copied this before
Expand Down
27 changes: 18 additions & 9 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,20 @@ Shell writes to repo files are sandboxed; edit through the editor tools, not
one left ownerless would have no plan, no billing and nobody who could
delete it. Settings names each org in the confirmation first. Orgs the
account only belongs to are untouched.
- **Bot protection**: Cap proof-of-work (`src/worker/cap.ts`, routes at
`/api/cap/:scope/{challenge,redeem}`) guards signup and password reset. The
token rides in an `x-cap-token` header and is spent in `hooks.before`. No
third party sees the visitor: `capjs-core` runs in this Worker, the widget
is bundled from npm, and the WASM solver is a same-origin Vite asset. Unset
`CAP_SECRET` disables it. See `docs/rate-limiting.md` for all three layers
(WAF rules, Workers limiters, Cap) and the dashboard rules to apply by hand.
- **Bot protection**: Cloudflare Turnstile (`src/worker/turnstile.ts`,
client in `src/app/lib/turnstile.ts`) guards signup and password reset
(an `x-turnstile-token` header, verified against `siteverify` in
`hooks.before`), the landing shortener (`/api/shorten`) and the report
form (`/api/reports`), each form with its own `action`. Cloudflare is the
one third party that sees the visitor, and only on those forms. Both keys
are secrets, set together (`turnstileMode`): with both, `/api/config`
serves the site key and the CSP admits `challenges.cloudflare.com` on
`APP_HOST`; with neither, the check is off and the browser never loads
Cloudflare's script; with one, every guarded form is refused and
`turnstile_misconfigured` is logged. Dev, CI and e2e use Cloudflare's
always-pass test keys. See `docs/rate-limiting.md` for all three layers
(WAF rules, Workers limiters, Turnstile) and the dashboard rules to apply
by hand.
- **KV keys**: `slug:{slug}` (shared host), `slug:{host}:{slug}` (custom domain),
`domain:{host}`. D1 is authoritative; KV is the redirect hot path. Clicks are
recorded via `waitUntil` after the redirect is sent, and store only
Expand Down Expand Up @@ -296,7 +303,7 @@ Shell writes to repo files are sandboxed; edit through the editor tools, not
- Data layer: `api()` + `ApiError` (`.status`, `.code`) in `src/app/lib/api.ts`;
TanStack Query hooks in `src/app/lib/hooks.ts`.
- **Strict CSP** on published pages, everything self-contained: no remote fonts,
images, scripts, or fetches. Icons via `lucide-react`; art via inline CSS/SVG. The one remote image is Fazier's launch badge in the landing footer, allowed in img-src for rdyrct.com's build only (their verifier needs their own image).
images, scripts, or fetches. Icons via `lucide-react`; art via inline CSS/SVG. The one remote image is Fazier's launch badge in the landing footer, allowed in img-src for rdyrct.com's build only (their verifier needs their own image). script-src and frame-src admit Cloudflare Turnstile's script and challenge iframe only on `APP_HOST` and only when both Turnstile keys are set.
- Email: `sendEmail()` (`src/worker/email.ts`) uses the Resend HTTP API via plain
`fetch`, with `RESEND_BASE_URL` pointing at the emulator in dev. Keep it: the
Resend SDK can't repoint its base URL, which would break the emulator flow.
Expand Down Expand Up @@ -334,7 +341,9 @@ and vars live in `wrangler.jsonc`; local dev reads everything from `.dev.vars`
`BETTER_AUTH_SECRET`, `SUPERADMIN_EMAIL`, `RESEND_API_KEY`, `MAIL_FROM`,
`APP_URL`, `APP_HOST`, `POLAR_ACCESS_TOKEN`/`POLAR_WEBHOOK_SECRET`/
`POLAR_PRO_PRODUCT_ID`/`POLAR_HOBBY_PRODUCT_ID`, `CF_API_TOKEN`/`CF_ZONE_ID`,
`SENTRY_DSN`, `WEB_RISK_API_KEY` (optional; unset skips Google Web Risk).
`TURNSTILE_SITE_KEY`/`TURNSTILE_SECRET_KEY` (optional; unset switches the
check off), `SENTRY_DSN`, `WEB_RISK_API_KEY` (optional; unset skips Google
Web Risk).

## Layout

Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,17 @@ Commit the rewritten `wrangler.jsonc` to your fork. After that, `bun run deploy`

Everything else is optional. Each piece says what it adds:

| Setting | Adds |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ |
| `RESEND_API_KEY`, `MAIL_FROM` | Email: sign-up verification codes, password reset, invites, notices. Without it, sign-up skips verification (see below). |
| `POLAR_*` | Selling Hobby and Pro plans. Without it, nobody is capped and billing is hidden. |
| `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET` | "Continue with Google". |
| `CF_API_TOKEN`, `CF_ZONE_ID` | Customers' own domains through Cloudflare for SaaS. |
| `SHARED_LINK_HOST` | A second, shorter host for new shared-domain links. |
| `CAP_SECRET` | Proof-of-work in front of sign-up and password reset. |
| `WEB_RISK_API_KEY` | Google Web Risk as a second destination check. A listed destination puts its link on hold. |
| `SENTRY_DSN` | Error reports to your Sentry project. |
| `SITE_NAME` | The name every tab shows, such as "Acme links". Without it, tabs show your copy's host. |
| Setting | Adds |
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `RESEND_API_KEY`, `MAIL_FROM` | Email: sign-up verification codes, password reset, invites, notices. Without it, sign-up skips verification (see below). |
| `POLAR_*` | Selling Hobby and Pro plans. Without it, nobody is capped and billing is hidden. |
| `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET` | "Continue with Google". |
| `CF_API_TOKEN`, `CF_ZONE_ID` | Customers' own domains through Cloudflare for SaaS. |
| `SHARED_LINK_HOST` | A second, shorter host for new shared-domain links. |
| `TURNSTILE_SITE_KEY`, `TURNSTILE_SECRET_KEY` | Cloudflare Turnstile in front of sign-up, password reset and the report form. Set both in one `wrangler secret bulk` call: one without the other refuses those forms. Cloudflare then sees those visitors. |
| `WEB_RISK_API_KEY` | Google Web Risk as a second destination check. A listed destination puts its link on hold. |
| `SENTRY_DSN` | Error reports to your Sentry project. |
| `SITE_NAME` | The name every tab shows, such as "Acme links". Without it, tabs show your copy's host. |

**With no email provider and no Google sign-in, accounts are not verified and passwords cannot be reset.** That is fine for a private instance and not recommended for a public one. The admin console says so while it is true.

Expand Down
21 changes: 1 addition & 20 deletions THIRD_PARTY_LICENSES.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,28 +170,9 @@ SOFTWARE.

## Apache License 2.0

`@cap.js/wasm`, `@cap.js/widget`, `capjs-core`, `drizzle-orm`, `posthog-js`
`drizzle-orm`, `posthog-js`
(dual Apache-2.0/MIT; see below for the vendored MIT-licensed portions)

### @cap.js/wasm, @cap.js/widget, capjs-core

```text
Copyright 2025 Tiago

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. (Full Apache License 2.0 text below, under
drizzle-orm.)
```

### drizzle-orm

```
Expand Down
Loading
Loading