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:
Aaron
2025-12-13 11:54:01 -07:00
committed by GitHub
parent 8fe06c68f3
commit 2d4b834fe8
2 changed files with 14 additions and 8 deletions

View File

@@ -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') {

View File

@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [accountingnerd]
---
Update validate-user.js to validate-user.ts.