feat(login): add request ip to the failed request log (#714)

This commit is contained in:
Jakob Ankarhem
2021-01-22 16:23:07 +01:00
committed by GitHub
parent 3ebb7d087f
commit 2d31ea940a
4 changed files with 23 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ import { getAppVersion } from './utils/appVersion';
import SlackAgent from './lib/notifications/agents/slack';
import PushoverAgent from './lib/notifications/agents/pushover';
import WebhookAgent from './lib/notifications/agents/webhook';
import { getClientIp } from '@supercharge/request-ip';
const API_SPEC_PATH = path.join(__dirname, '../overseerr-api.yml');
@@ -62,6 +63,21 @@ app
server.use(cookieParser());
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: true }));
server.use((req, res, next) => {
try {
const descriptor = Object.getOwnPropertyDescriptor(req, 'ip');
if (descriptor?.writable === true) {
req.ip = getClientIp(req) ?? '';
}
} catch (e) {
logger.error('Failed to attach the ip to the request', {
label: 'Middleware',
message: e.message,
});
} finally {
next();
}
});
// Setup sessions
const sessionRespository = getRepository(Session);

View File

@@ -151,6 +151,7 @@ authRoutes.post('/local', async (req, res, next) => {
logger.info('Failed login attempt from user with incorrect credentials', {
label: 'Auth',
account: {
ip: req.ip,
email: body.email,
password: '__REDACTED__',
},