Note · budding
Single sign-on, and the test that read my SQL
- Stage
- budding
- Links
- 1 out, 1 in
Inbound Outbound keeps many organisations in one D1 database. The rule is that every query filters on org_id. A test enforces it: tests/security-scan.test.ts reads every SQL string in worker/, finds the ones that touch a tenant table, and fails unless the statement compares org_id or is listed in LOOSE with a reason it cannot cross tenants. It covers more than 300 statements.
What it caught
I added single sign-on with OpenID Connect and two of the five scan tests failed. My table of sign-ins in progress had no org_id, so the test counted it as a global table, and global tables are meant to be the two identity tables only. Six statements were also unscoped. The sign-in routes run before a session exists, so they look a provider up by its id. I added org_id to the state table, scoped what could be scoped, and wrote a reason for each statement that could not. The reasons are the review: a new unscoped query fails until someone writes one.
The sign-in
- Authorization code flow with PKCE. The state is stored as a SHA-256 hash for 10 minutes, used once, and tied to the browser by a cookie, so an attacker cannot hand a victim a sign-in they started.
- The id token must carry a valid RS256 or ES256 signature from the provider’s keys, and the right issuer, audience, expiry and nonce.
noneand HMAC are refused. - A provider lists the email domains it signs in. Public mail domains are refused.
- A person with an account in another organisation is never linked. The owner of an organisation is never signed in this way. A provider cannot assign the owner role.
- A session from single sign-on lasts the provider’s setting, 8 hours by default. The provider can end it early with a back-channel logout, and switching a provider off ends its sessions.
What is untested
The flow runs against a stand-in provider in the tests. It has not run against Entra, Google, Okta, Auth0 or Keycloak. Domain claims are not verified, so any organisation can list a domain it does not own. The sign-in still refuses an address on a domain the provider does not list.
Projects
- Inbound OutboundA multi-tenant SaaS for booking vehicles into a warehouse and calling them to a dock, built on Cloudflare in three days as a test of building real full-stack cloud applications.
Projects
- Inbound OutboundA multi-tenant SaaS for booking vehicles into a warehouse and calling them to a dock, built on Cloudflare in three days as a test of building real full-stack cloud applications.