mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-11 07:00:47 +02:00
Merge pull request #15822 from overleaf/mj-audit-log-tokens
[web] Add audit logs for token expiration operations GitOrigin-RevId: 220fe017cf508ead986a4cd2bd9009035418ce43
This commit is contained in:
committed by
Copybot
parent
720e5bdc4d
commit
5e083dffd5
@@ -14,6 +14,9 @@ const { expressify } = require('@overleaf/promise-utils')
|
||||
const AsyncFormHelper = require('../Helpers/AsyncFormHelper')
|
||||
const AnalyticsManager = require('../Analytics/AnalyticsManager')
|
||||
const UserPrimaryEmailCheckHandler = require('../User/UserPrimaryEmailCheckHandler')
|
||||
const UserAuditLogHandler = require('./UserAuditLogHandler')
|
||||
|
||||
const AUDIT_LOG_TOKEN_PREFIX_LENGTH = 10
|
||||
|
||||
async function _sendSecurityAlertEmail(user, email) {
|
||||
const emailOptions = {
|
||||
@@ -267,7 +270,7 @@ const UserEmailsController = {
|
||||
}
|
||||
UserEmailsConfirmationHandler.confirmEmailFromToken(
|
||||
token,
|
||||
function (error) {
|
||||
function (error, userData) {
|
||||
if (error) {
|
||||
if (error instanceof Errors.NotFoundError) {
|
||||
res.status(404).json({
|
||||
@@ -277,7 +280,24 @@ const UserEmailsController = {
|
||||
next(error)
|
||||
}
|
||||
} else {
|
||||
res.sendStatus(200)
|
||||
const { userId, email } = userData
|
||||
const tokenPrefix = token.substring(0, AUDIT_LOG_TOKEN_PREFIX_LENGTH)
|
||||
UserAuditLogHandler.addEntry(
|
||||
userId,
|
||||
'confirm-email',
|
||||
userId,
|
||||
req.ip,
|
||||
{ token: tokenPrefix, email },
|
||||
auditLogError => {
|
||||
if (auditLogError) {
|
||||
logger.error(
|
||||
{ error: auditLogError, userId, token: tokenPrefix },
|
||||
'failed to add audit log entry'
|
||||
)
|
||||
}
|
||||
res.sendStatus(200)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user