[FIX] Prevent user creation for custom OAuth when registration is disabled and LDAP is enabled #22564
+11
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When the
Accounts_Registration_AuthenticationServices_Enabled
is set asfalse
, the user should not be created via custom OAuth service.Proposed changes (including videos or screenshots)
Issue(s)
Resolve #15787, resolves #20671
Steps to test or reproduce
When
Accounts_Registration_AuthenticationServices_Enabled
is set asfalse
, the user try to sign in with custom OAuth service will be blocked with logException while invoking method login Error: User registration is disabled for authentication services [registration-disabled-authentication-services]
, which is as exceptedHowever, when the
LDAP_Enable
is set astrue
, the rule breaks because the validation checks if both of the two configs are false, see:3.16.1/app/authentication/server/startup/index.js#L366
This is UNEXPECTED as you could think of those who need the custom OAuth service may often have their LDAP enabled for such an on-premise server.
In our case, we pre-sync part of the users to our server with LDAP but do NOT want all of the users that can pass the OAuth service to register a new account automatically.
Further comments
By further checking the
settings.get(/^Accounts_OAuth_Custom-[a-z0-9_]+$/i).length > 0
, we are able to prevent user from create their account automatically./^Accounts_OAuth_Custom-[a-z0-9_]+$/i
refers tooAuthServicesUpdate.js#L19
serviceName.replace(/^Accounts_OAuth_Custom-/, '').toLowerCase()
refers toaddOAuthService.js#L8
, which limits the name of custom OAuth service as lowercase (i.e.,[a-z0-9_]+
)Dev Environment
Rocket.Chat@3.15.0
+Keycloak
as custom OAuth service providerResults