Skip to content

Security: diffplug/pgstencil

Security

SECURITY.md

pgstencil security

pgstencil ships pgstencil, @pgstencil/auth and @pgstencil/stripe as packed tarballs (PACKAGES.md). This file states what the Better Auth integration in @pgstencil/auth, the Billing class in @pgstencil/stripe, and pgstencil itself guarantee to a consuming application, as conditions an auditor can check at one commit; each section ends with the tests that pin them. Bare names are under packages/auth/src/, packages/auth/better-auth-migrations/, packages/stripe/migrations/ or tests/; in the billing sections a bare method or constant is a member of Billing, or an export, in packages/stripe/src/index.ts.

The application owns everything outside the packages: TLS and its origin gate, the CSP of its own pages, secret and credential storage, database provisioning, provider registration, and — only when it opts in with ipAddressHeaders — a proxy that overwrites those headers on every request. For billing it also owns: authenticating the owner before every Billing call that takes an owner ID, and never taking that ID, a customer, Price, quantity or URL from the browser; CSRF and exact-origin checks on its billing routes; handing each webhook's raw body and Stripe-Signature header to webhook or verifyWebhook unaltered, under a body limit, and answering 2xx only after webhook resolves; storing the Stripe secret key and the webhook signing secret; and the Stripe account itself — its Prices, a customer portal that offers no Price outside prices, no quantity change and no second subscription, and a webhook endpoint created at STRIPE_API_VERSION. The example in examples/better-auth/ shows one way to do this, exercised by integration/billing-http.test.ts.

Sessions and cookies

  • FAIL IF an HTTPS deployment's auth cookies lack __Host-, Secure, HttpOnly, Path=/ or SameSite=Lax, or carry Domain; inspect better-auth.ts and better-auth-security.ts.
  • FAIL IF a session token, a provider access/refresh/ID token or the internal singleSession/emailAuthenticated fields reach browser JSON, a stored session token authenticates without the server's cookie signature, or a bearer or API-key plugin is enabled; inspect publicAuthResponse and plugins.
  • FAIL IF sessions outlive 24 hours, refresh on use, come from a cookie cache instead of the database, or session creation stops being serialized per user; inspect session in better-auth.ts and 002_security_policy.sql.
  • FAIL IF sessionPolicy: 'single' leaves another device signed in, 'multiple' (the default) revokes one, or sign-out revokes another session; inspect databaseHooks.session.
  • FAIL IF the readable rememberLoginMethod cookie grants authority, records a failed attempt or an explicit link, or is written to the database; inspect lastLoginMethod in better-auth.ts.
  • FAIL IF an application hook receives anything but the login method, runs before its write commits, fires for an explicit link or a failed attempt, or can fail or delay the auth response by throwing, rejecting or never settling; inspect runHook, loginMethod and databaseHooks in better-auth.ts, and hooks in better-auth-workers.ts.

Pinned by integration/better-auth.test.ts: email policy: secret-keyed codes, cross-browser redemption, concurrent single use and no token exposure, Better Auth time: 23 hours, expiration boundary, isolated async contexts and unchanged host clock, session policy: single, session policy: multiple; integration/better-auth-oauth.test.ts: Last login method remembers only successful sign-ins and survives logout, Auth hooks see each sign-up and login after it commits, and never a link or a failure,