[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-20 10:06:28 +02:00
committed by Copybot
parent 2233ac9b1d
commit 107189cd5f
5 changed files with 74 additions and 26 deletions
@@ -0,0 +1,39 @@
import bcrypt from 'bcrypt'
import { db } from './lib/mongodb.mjs'
import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
import { promiseMapWithLimit } from '@overleaf/promise-utils'
const tags = ['server-ce', 'server-pro']
const HARDCODED_PASSWORD = 'password_here'
const CONCURRENCY = parseInt(process.env.CONCURRENCY, 10) || 10
const migrate = async () => {
await batchedUpdate(
db.users,
{ hashedPassword: { $type: 'string' } },
async function (batch) {
await promiseMapWithLimit(CONCURRENCY, batch, async user => {
const match = await bcrypt.compare(
HARDCODED_PASSWORD,
user.hashedPassword
)
if (match) {
await db.users.updateOne(
{ _id: user._id, hashedPassword: user.hashedPassword },
{ $unset: { hashedPassword: 1 } }
)
}
})
},
{ hashedPassword: 1 }
)
}
const rollback = async () => {}
export default {
tags,
migrate,
rollback,
}
+1
View File
@@ -11,6 +11,7 @@
"@overleaf/o-error": "workspace:*",
"@overleaf/promise-utils": "workspace:*",
"@overleaf/settings": "workspace:*",
"bcrypt": "^6.0.0",
"east": "2.0.3",
"mongodb": "6.12.0"
}