Repository navigation
Conversation
OAuthController::callBack() created a new user for any unknown email
returned by the OAuth provider, checking only the per-service
`allow_register` flag. It never consulted Shield's global
`Auth.allowRegistration` setting, so apps that disabled registration
in Shield (in app/Config/Auth.php or via `auth.allowRegistration =
false` in .env) could still have accounts created through any enabled
OAuth service.
The per-service check also failed open: it only blocked when
`allow_register` was strictly `false`, so a service config missing the
key permitted registration.
Changes:
- Add isShieldRegistrationAllowed(), which checks
setting('Auth.allowRegistration') === true. When it is false the user
is redirected with Shield's own `Auth.registerDisabled` message,
matching Shield's RegisterController.
- Add isOAuthRegistrationAllowed(), which only allows registration when
the service's `allow_register` is exactly `true` (fails closed when
the key is missing).
- Both checks run before any user record is created. Existing users can
still log in through OAuth; only new account creation is gated.
- Document how the two settings interact in docs/install.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Summary
Shield OAuth creates accounts even when Shield's registration is turned off.
OAuthController::callBack()registers any email it doesn't recognise and never checks Shield'sAuth.allowRegistrationsetting. On an app that has disabled registration (public bool $allowRegistration = false;inapp/Config/Auth.php, orauth.allowRegistration = falsein.env), anyone can still sign up just by using an enabled OAuth button.This PR makes the OAuth callback honour that setting and closes a related fail-open in the per-service check.
The problem
1. Shield's global registration switch is ignored
Before creating a user, the callback only looked at the service's own flag:
Shield's
RegisterControllerblocks registration whensetting('Auth.allowRegistration')is false, but OAuth goes around it. An admin who turns off registration in Shield would reasonably expect that to cover every way of creating an account.2. The per-service check fails open
The check only blocks when
allow_registeris exactlyfalse. If a service config has noallow_registerkey (a hand-written config for a custom provider, say), registration is allowed. When the key is missing, PHP also raises an "undefined array key" warning.The fix
Two small private helpers in
OAuthController, both run before any user record is written:isShieldRegistrationAllowed()setting('Auth.allowRegistration') === trueAuth.registerDisabled(Shield's own message, same as its register page)isOAuthRegistrationAllowed($oauthName)allow_registeris exactlytrue; a missing key counts as not allowedShieldOAuthLang.Callback.account_not_found(unchanged)Because it goes through
setting(), the global check picks up the value fromapp/Config/Auth.php,.envoverrides and the Settings database, just like Shield does.I also added a short "Controlling Registration" section to
docs/install.mdexplaining how the two settings work together.Behaviour changes
logoutRedirect()with Shield's "registration is not allowed" message.allow_loginistrue), just as Shield's password login keeps working.allow_registerkey: that service now refuses to create new accounts. The bundled GitHub and Google configs, themake:oauthgenerator template and the docs all set the key totrue, so default setups behave the same as before.How to test
auth.allowRegistration = falsein.env. Keepallow_register => truefor GitHub/Google.users.auth.allowRegistration = trueagain and repeat step 2. The account is created as before.allow_registerfrom one service's config and repeat step 2. Registration through that service is refused.Notes
registerevent). Both PRs touch the sameelsebranch incallBack(), but in different hunks, so they should merge cleanly in either order.🤖 Generated with Claude Code
Summary by CodeRabbit