fixed sonarqube findings
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import crypto from 'node:crypto';
|
||||
import { isLoopbackAddress } from './route-write-access.js';
|
||||
import { guardPoint, clearPointLocks, hasPointLocks } from './point-locks.js';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
@@ -163,7 +164,7 @@ export function listGroups(db, req) {
|
||||
}
|
||||
|
||||
function failureKey(req) {
|
||||
const localProxy = ['127.0.0.1', '::1', '::ffff:127.0.0.1'].includes(req.socket?.remoteAddress);
|
||||
const localProxy = isLoopbackAddress(req.socket?.remoteAddress);
|
||||
return hash(String(localProxy && req.headers['x-real-ip'] || req.socket?.remoteAddress || 'unknown'));
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,10 @@ function read(routeId, poiId) {
|
||||
}
|
||||
return lock;
|
||||
}
|
||||
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
||||
catch (error) {
|
||||
if (error.code === 'ENOENT') return null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
function write(routeId, poiId, lock) {
|
||||
const target = filename(routeId, poiId);
|
||||
@@ -86,7 +89,10 @@ export function hasPointLocks(routeId) {
|
||||
const directory = path.join(routeDirectory(routeId), 'locks');
|
||||
let entries;
|
||||
try { entries = fs.readdirSync(directory, { withFileTypes: true }); }
|
||||
catch (error) { if (error.code === 'ENOENT') return false; throw error; }
|
||||
catch (error) {
|
||||
if (error.code === 'ENOENT') return false;
|
||||
throw error;
|
||||
}
|
||||
let locked = false;
|
||||
for (const entry of entries) {
|
||||
if (entry.isFile() && /^\d+\.json$/.test(entry.name) && read(routeId, Number(entry.name.slice(0, -5)))) locked = true;
|
||||
|
||||
@@ -13,7 +13,7 @@ function hasForwardingHeader(req, name) {
|
||||
return value != null && String(value).trim().length > 0;
|
||||
}
|
||||
|
||||
function isLoopbackAddress(address) {
|
||||
export function isLoopbackAddress(address) {
|
||||
if (typeof address !== 'string' || address.length === 0) return false;
|
||||
if (address === '::1') return true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user