mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-29 02:54:09 -05:00
typescript: update validate-user.js to validate-user.ts (#6142)
* typescript: update validate-user.js to validate-user.ts * fix capitalization in release notes.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { type Request, type Response } from 'express';
|
||||
import ipaddr from 'ipaddr.js';
|
||||
|
||||
import { getSession } from '../account-db';
|
||||
@@ -6,11 +7,7 @@ import { config } from '../load-config';
|
||||
export const TOKEN_EXPIRATION_NEVER = -1;
|
||||
const MS_PER_SECOND = 1000;
|
||||
|
||||
/**
|
||||
* @param {import('express').Request} req
|
||||
* @param {import('express').Response} res
|
||||
*/
|
||||
export function validateSession(req, res) {
|
||||
export function validateSession(req: Request, res: Response) {
|
||||
let { token } = req.body || {};
|
||||
|
||||
if (!token) {
|
||||
@@ -44,18 +41,21 @@ export function validateSession(req, res) {
|
||||
return session;
|
||||
}
|
||||
|
||||
export function validateAuthHeader(req) {
|
||||
export function validateAuthHeader(req: Request) {
|
||||
// fallback to trustedProxies when trustedAuthProxies not set
|
||||
const trustedAuthProxies =
|
||||
const trustedAuthProxies: string[] =
|
||||
config.get('trustedAuthProxies') ?? config.get('trustedProxies');
|
||||
// ensure the first hop from our server is trusted
|
||||
const peer = req.socket.remoteAddress;
|
||||
if (peer === undefined) {
|
||||
console.error(`Header Auth Login attempted but there was no defined peer.`);
|
||||
return false;
|
||||
}
|
||||
const peerIp = ipaddr.process(peer);
|
||||
const rangeList = {
|
||||
allowed_ips: trustedAuthProxies.map(q => ipaddr.parseCIDR(q)),
|
||||
};
|
||||
|
||||
// @ts-ignore : there is an error in the ts definition for the function, but this is valid
|
||||
const matched = ipaddr.subnetMatch(peerIp, rangeList, 'fail');
|
||||
|
||||
if (matched === 'allowed_ips') {
|
||||
6
upcoming-release-notes/6142.md
Normal file
6
upcoming-release-notes/6142.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Maintenance
|
||||
authors: [accountingnerd]
|
||||
---
|
||||
|
||||
Update validate-user.js to validate-user.ts.
|
||||
Reference in New Issue
Block a user