Files
lunch/lib/auth/request.ts
T
Kai BöhmandClaude Opus 5.5 f423dd67ce
ci / olares chart · sanity (pull_request) Successful in 3s
ci / app · types + tests + build (pull_request) Successful in 3m7s
markt / eintrag (pull_request) Successful in 29s
release / which version (pull_request) Successful in 3s
release / olares chart · sanity (pull_request) Successful in 4s
release / app (pull_request) Successful in 59s
release / tag and release (pull_request) Skipped
Own sign-in with passkeys, open the entrance, market entry (26.11.2)
Setup with a code from /app/data, passkeys with required user
verification, sessions as hashed cookies bound to the passkey they
started with, single-use invitation and device links, removing a
passkey or a member, and a recovery code for the owner. Cross-household
lookups before sign-in run in withAuth() (app.auth), allowed only on the
sign-in tables; a test pins that list. State-changing routes check the
session and the Origin header.

Security check with the login-sicherheit skill before the first
invitation: docs/sicherheit/login-2026-11-06.md (no open findings above
low). Entrance goes public now that the own sign-in exists; markt.yml
creates the Lunch entry in aimighty-market and proves it with wrangler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUc2nv7rJVU2gp3Bgtha3q
2026-11-06 19:26:36 +00:00

29 lines
1021 B
TypeScript

import "server-only";
/**
* Die Adresse der App, wie der Browser sie sieht: aus dem Origin-Kopf, den
* der Browser bei jedem POST selbst setzt. Hinter Olares (Envoy, TLS davor)
* ist das verlässlicher als Host und X-Forwarded-*.
*/
export function browserOrigin(request: Request): URL | null {
const origin = request.headers.get("origin");
if (!origin) return null;
try {
const url = new URL(origin);
return url.protocol === "https:" || url.protocol === "http:" ? url : null;
} catch {
return null;
}
}
/**
* Für die Bremse. Envoy hängt die Adresse an; die erste ist die des Geräts —
* aber ein Gerät kann selbst einen Kopf mitschicken. Deshalb hat jede Bremse
* zusätzlich einen gemeinsamen Topf („…:*“), der nicht von der Adresse abhängt.
*/
export function clientIp(request: Request): string {
const forwarded = request.headers.get("x-forwarded-for");
const first = forwarded?.split(",")[0]?.trim();
return first || request.headers.get("x-real-ip") || "unknown";
}