mirror of
https://github.com/directus/directus.git
synced 2026-04-03 03:00:39 -04:00
18 lines
620 B
TypeScript
18 lines
620 B
TypeScript
import { RequestHandler } from 'express';
|
|
import asyncHandler from '../utils/async-handler';
|
|
import database from '../database';
|
|
import { InvalidIPException } from '../exceptions';
|
|
|
|
export const checkIP: RequestHandler = asyncHandler(async (req, res, next) => {
|
|
const role = await database
|
|
.select('ip_access')
|
|
.from('directus_roles')
|
|
.where({ id: req.accountability!.role })
|
|
.first();
|
|
|
|
const ipAllowlist = (role?.ip_access || '').split(',').filter((ip: string) => ip);
|
|
|
|
if (ipAllowlist.length > 0 && ipAllowlist.includes(req.accountability!.ip) === false) throw new InvalidIPException();
|
|
return next();
|
|
});
|