Back to Field Notes
Log

October 29: Sign in with Infinary on main, switched off, and a session nobody could leave

All four parts of Sign in with Infinary merged in one day, none of them deployed, and the site side taught us three things about Frappe's Single DocTypes. It started with a browser stuck as our own agent user, unable even to log out.

Covers
Written
Repositories
infinary.io, infinary_controls
Pull requests
5
Status
In progress
Reading time
6 min
#single-sign-on#openid-connect#frappe#control-plane#infinary-controls#review
Contents

Six pull requests merged across two repositories, one of them the previous log. Four were Sign in with Infinary, the plan for the hub to vouch for people on their own hosted ERPNext sites that was accepted the day before. The hub’s provider (infinary.io PR #365), what each site is told about it (#366), the account chooser in the portal (#367), and the site’s side in Infinary Controls (infinary_controls PR #73) are all on their main branches. None of it is deployed, the provider stays switched off, and the Controls side has no release yet. The sixth fixed a problem we caused ourselves.

PRs merged, besides Field Notes
5
of them Sign in with Infinary
4
of those deployed
0
review rounds on the site side
5

The session nobody could leave

On the 28th, Nikolas used ERPNext’s Impersonate, from Desk on a hosted site, to see what our agent user could see. Infinary Controls only lets that user make signed requests: a guard checks every request made as it and refuses anything unsigned. A browser session isn’t signed, so the guard refused every page, Log out included, and the browser stayed stuck until its cookies were cleared. Nothing stopped a System Manager from impersonating that user, and nothing let the session leave.

The fix (infinary_controls PR #72) has two halves:

  • Nobody signs in as the agent user. Impersonate, a password login, an email link, a password reset and a social login all pass through the same point in Frappe, the on_login hook, before a session is made. One hook refuses all of them, with a message saying to use your own login instead. Signed calls never reach that hook, so the agent itself is untouched.
  • A session that already exists can log out, and do nothing else. The guard has one exit, an exact match on GET /logout, and only for a browser session with no query string.

The tests use a fake Frappe, so a script checks the same things on a real bench: impersonation refused with the admin still signed in, and a planted agent session refused, then ended at /logout. It ran on a site built from our golden image before the merge. The fix is on main; it reaches sites with the next Controls release.

Sign in with Infinary, all four parts

The design’s main choice holds all the way through: a site proves who it is with a key it already holds, its instance key, so no client secret exists anywhere.

  • The provider (infinary.io PR #365) is OpenID Connect with PKCE required, codes that last 60 seconds and work once, and short-lived access tokens good only for reading who signed in. With the switch unset, every new route answers exactly as an unknown path does. The hub vouches for an email only if it was seen at a sign-in and only one account holds it, which is what the accounts rehearsal taught us.
  • Each site is told whether it’s on, in a block signed with a hub key the site already trusts (#366). An unsigned or wrongly signed block changes nothing. Staff can switch a site off from the admin page; the hub refuses it at once, and the site hides its button within 15 minutes.
  • The account chooser (#367) shows the site and the account, and says what the site will learn: a name and an email, nothing else. A first review found that the chooser ran inside the portal’s usual shell, which creates an Infinary organization the first time someone signs in, so a site’s users would have gained one they never asked for. It now runs under a bare shell that creates nothing. Nikolas decided a site choice lasts 90 days since it was last used.
  • The site side (infinary_controls PR #73) is the client. Stock Frappe has social logins, and the spike that started this PR read its source to see how far they go: it never compares the account id it stored again, and it accepts any email as verified. Our callback checks both, and our agent and Aria users can never sign in this way.

Independent reviews went over each part before merge. On the provider, one finding was that the chooser could be skipped. Continuing now needs a form POST from the portal in the same browser.

Three things Frappe’s Singles taught us

Most of the site side’s five review rounds were about one kind of record. A Frappe Single holds settings: one row of fields, no list. The site keeps the hub’s latest block in one, and the hub can change it every 15 minutes.

  1. Writing one field bumps modified. Frappe 16’s set_single_value updates the Single’s modified time unless you pass update_modified=False. Every background pull did that, though the pull was written to leave the record alone. A test now pins that no field write moves modified.
  2. A stale save brings old values back. With pulls no longer touching modified, a form opened before a pull would save its older copy of the block over the new one: an “on” over the hub’s “off”. The settings’ validation now re-reads the hub’s fields from the database before saving. Then, chasing a bench failure, we found that under MariaDB’s default repeatable read, a plain read returns the snapshot the request took at its first read, which can predate the pull. That read now locks (for_update=True) and sees the latest committed row.
  3. An encrypted field needs its mask. Frappe stores a password field’s value in a separate table, and keeps a mask in the record. Our bench script stored only the value, so the next full save of the Single, seeing an empty field, deleted the key. Production code already wrote the mask; the script didn’t, so a passing check in round 3 meant nothing until round 4 fixed it.

Controls’ test suite went from 1,459 passing before the site side to 1,597 at its last local run.

Also

  • Control-plane tests went from 937 on the morning’s main to 1,031 on the C2b branch at its last review, with none failing in that last run. The Firestore-emulator tests still weren’t run locally, because they need Java 21.
  • The portal is set to send headers that stop its pages being framed, to be checked once it’s next deployed, and the chooser keeps a referrer policy that always sends a real origin with its form.
  • The previous log merged after its Kremio test count was corrected.