[web] Clear hardcoded password in external SP auth (#33597)

registerExternalAuthAdmin() now generates a random password on admin registration.

A migration clears the password for existing installs only in CE/SP

GitOrigin-RevId: 94a82d35dc8cd46915c31fb24f477c19367025eb
This commit is contained in:
Miguel Serrano
2026-05-21 08:06:07 +00:00
committed by Copybot
parent 2233ac9b1d
commit 107189cd5f
5 changed files with 74 additions and 26 deletions
@@ -2,6 +2,7 @@ import OError from '@overleaf/o-error'
import { expressify } from '@overleaf/promise-utils'
import Settings from '@overleaf/settings'
import Path from 'node:path'
import crypto from 'node:crypto'
import logger from '@overleaf/logger'
import UserRegistrationHandler from '../../../../app/src/Features/User/UserRegistrationHandler.mjs'
import EmailHandler from '../../../../app/src/Features/Email/EmailHandler.mjs'
@@ -124,12 +125,12 @@ function registerExternalAuthAdmin(authMethod) {
const body = {
email,
password: 'password_here',
password: crypto.randomBytes(32).toString('hex'),
first_name: email,
last_name: '',
}
logger.debug(
{ body, authMethod },
{ email, authMethod },
'creating admin account for specified external-auth user'
)
@@ -759,14 +759,16 @@ describe('LaunchpadController', function () {
ctx.UserRegistrationHandler.promises.registerNewUser.callCount.should.equal(
1
)
ctx.UserRegistrationHandler.promises.registerNewUser
.calledWith({
email: ctx.email,
password: 'password_here',
first_name: ctx.email,
last_name: '',
})
.should.equal(true)
const call =
ctx.UserRegistrationHandler.promises.registerNewUser.firstCall
expect(call.args[0]).to.include({
email: ctx.email,
first_name: ctx.email,
last_name: '',
})
expect(call.args[0].password).to.be.a('string')
expect(call.args[0].password).to.not.equal('password_here')
expect(call.args[0].password.length).to.be.at.least(16)
})
it('should have updated the user to make them an admin', function (ctx) {
@@ -964,14 +966,16 @@ describe('LaunchpadController', function () {
ctx.UserRegistrationHandler.promises.registerNewUser.callCount.should.equal(
1
)
ctx.UserRegistrationHandler.promises.registerNewUser
.calledWith({
email: ctx.email,
password: 'password_here',
first_name: ctx.email,
last_name: '',
})
.should.equal(true)
const call =
ctx.UserRegistrationHandler.promises.registerNewUser.firstCall
expect(call.args[0]).to.include({
email: ctx.email,
first_name: ctx.email,
last_name: '',
})
expect(call.args[0].password).to.be.a('string')
expect(call.args[0].password).to.not.equal('password_here')
expect(call.args[0].password.length).to.be.at.least(16)
})
it('should not call update', function (ctx) {
@@ -1015,14 +1019,16 @@ describe('LaunchpadController', function () {
ctx.UserRegistrationHandler.promises.registerNewUser.callCount.should.equal(
1
)
ctx.UserRegistrationHandler.promises.registerNewUser
.calledWith({
email: ctx.email,
password: 'password_here',
first_name: ctx.email,
last_name: '',
})
.should.equal(true)
const call =
ctx.UserRegistrationHandler.promises.registerNewUser.firstCall
expect(call.args[0]).to.include({
email: ctx.email,
first_name: ctx.email,
last_name: '',
})
expect(call.args[0].password).to.be.a('string')
expect(call.args[0].password).to.not.equal('password_here')
expect(call.args[0].password.length).to.be.at.least(16)
})
})
})