mirror of
https://github.com/Ride-The-Lightning/RTL.git
synced 2026-08-13 12:33:07 +02:00
* Update version 0.15.10 * Update project dependencies to resolve Dependabot security alerts Applies the fixes from the open Dependabot PRs (#1648, #1649, #1650) in a single pass on the release branch, regenerating the lockfile from scratch. axios 1.16.0 -> 1.18.1 was the only production exposure (10 advisories). Transitive deps moved to their fixed in-range versions (fast-uri 3.1.4, form-data, qs, tough-cookie, tar, del, globby); dev toolchain took safe bumps (nodemon 3.1.14, eslint 9.39.5, @typescript-eslint 8.65.0). Drops the unused protractor devDependency: no e2e directory, no config and no e2e target in angular.json, but 100 packages and the deprecated request stack behind it. That clears both critical advisories. npm audit: 50 (2 critical) -> 29 (0 critical); production deps 1 -> 0. Remaining findings are dev-only tooling needing an Angular 21 migration rather than a version bump. Verified: lint, 204 frontend specs, backend + frontend production builds, and 19 API checks against the docker regtest fixture covering LND, Core Lightning and Eclair (getinfo, channels, peers, invoices, payments and forwarding history). * Fill in PR number in release note (#1653) * Harden login request validation (#1654) Tightens server-side validation of authentication requests, guards the password-reset route behind an authenticated session, and wires the backend regression suite (test/backend/) into npm run test. Users with two-factor authentication enabled are encouraged to update promptly. Verified: backend specs 12/12, lint green, frontend specs 204/204, and the full authentication matrix end-to-end on the docker regtest fixture. * Reduce exposure of authentication secrets in logs and config responses (#1659) * Reduce exposure of authentication secrets in logs and config responses * Fill in PR number in release note (#1659) * Harden redaction helpers and secret restore paths * Pin deployment auth switches server-side and harden settings persistence * Contain backup file reads and harden config persistence * Pin backup containment root and preserve config file mode on save * Update Angular framework packages to 20.3.27 (#1661) * Update Angular framework packages to 20.3.27 Batches the three Dependabot PRs open against master for the Angular framework (@angular/core #1658, @angular/compiler #1657, @angular/common #1655) into one update on the release branch. The framework packages are pinned to exact versions and their peer ranges require them to move together, so all nine 20.3.26 packages go to 20.3.27: animations, common, compiler, compiler-cli, core, forms, platform-browser, platform-browser-dynamic and router. Patch-level upstream fixes only, no advisories. The update stays inside Angular 20 - @angular/build and @angular/cli (20.3.32) and @angular/cdk/@angular/material (20.2.14) are already at the top of their v20 lines - so it does not pull in the Angular 21 migration tracked by #1650. Rebuilt frontend/ for the new framework code. backend/ is unchanged, as no server/ source moved. * Fill in PR number in release note (#1661) * Bound remaining unbounded alias-resolution fan-outs in LND graph.ts and channels.ts Fixes #1630 (#1651) * Bound remaining unbounded alias-resolution fan-outs in LND graph.ts and channels.ts Fixes #1630 * Address review feedback: fix options race, error handling, release notes * Improve release notes entry to cover full PR scope * Address review feedback: per-task options copy, exclude qs from alias requests * Stop logging the eclair auth header at DEBUG level (#1664) * Stop logging the eclair auth header at DEBUG level getChannels in the eclair channels controller logged its whole request options object. Eclair authenticates with HTTP basic auth, so those options carry the configured lnApiPassword in an authorization header - raising an eclair node's logLevel to DEBUG wrote "authorization":"Basic <base64>" into the node log file, which is a recoverable form of the credential and is routinely shared when debugging. The log now carries only the request url and form, matching every other DEBUG log in the controllers. This was the only site in server/ passing a whole options object to the logger; the rest log options.form, .url, .body or .qs, none of which hold credentials. Present since 0.12.0 and only reachable by opting in to DEBUG (the default log level is ERROR), but it contradicted the logging guarantee stated for #1659. Found by scanning node logs at DEBUG while verifying the 0.15.10 branch against the regtest fixture. Regression test added in test/backend/eclair-channels.test.mjs; it fails on the previous code with "auth header key must not reach the node log". * Fill in PR number in release note (#1664) --------- Co-authored-by: Osuji <weezdomosuji@gmail.com>
167 lines
9.4 KiB
JavaScript
167 lines
9.4 KiB
JavaScript
import jwt from 'jsonwebtoken';
|
|
import * as otplib from 'otplib';
|
|
import * as crypto from 'crypto';
|
|
import { Database } from '../../utils/database.js';
|
|
import { Logger } from '../../utils/logger.js';
|
|
import { Common } from '../../utils/common.js';
|
|
const logger = Logger;
|
|
const common = Common;
|
|
const ONE_MINUTE = 60000;
|
|
const LOCKING_PERIOD = 30 * ONE_MINUTE; // HALF AN HOUR
|
|
const ALLOWED_LOGIN_ATTEMPTS = 5;
|
|
const failedLoginAttempts = {};
|
|
const databaseService = Database;
|
|
const loginInterval = setInterval(() => {
|
|
for (const ip in failedLoginAttempts) {
|
|
if (new Date().getTime() > (failedLoginAttempts[ip].lastTried + LOCKING_PERIOD)) {
|
|
delete failedLoginAttempts[ip];
|
|
clearInterval(loginInterval);
|
|
}
|
|
}
|
|
}, LOCKING_PERIOD);
|
|
// The sweeper must not hold the event loop open on its own (it would keep
|
|
// `node --test` or a CLI invocation alive for the full 30-minute period).
|
|
loginInterval.unref();
|
|
export const getFailedInfo = (reqIP, currentTime) => {
|
|
let failed = { count: 0, lastTried: currentTime };
|
|
if ((!failedLoginAttempts[reqIP]) || (currentTime > (failed.lastTried + LOCKING_PERIOD))) {
|
|
failed = { count: 0, lastTried: currentTime };
|
|
failedLoginAttempts[reqIP] = failed;
|
|
}
|
|
else {
|
|
failed = failedLoginAttempts[reqIP];
|
|
}
|
|
return failed;
|
|
};
|
|
const handleMultipleFailedAttemptsError = (failed, currentTime, errMsg) => {
|
|
if (failed.count >= ALLOWED_LOGIN_ATTEMPTS && (currentTime <= (failed.lastTried + LOCKING_PERIOD))) {
|
|
return {
|
|
message: 'Multiple Failed Login Attempts!',
|
|
error: 'Application locked for ' + (LOCKING_PERIOD / ONE_MINUTE) + ' minutes due to multiple failed attempts!\nTry again after ' + common.convertTimestampToTime((failed.lastTried + LOCKING_PERIOD) / 1000) + '!'
|
|
};
|
|
}
|
|
else {
|
|
return {
|
|
message: 'Authentication Failed!',
|
|
error: errMsg + '\nApplication will be locked after ' + (ALLOWED_LOGIN_ATTEMPTS - failed.count) + ' more unsuccessful attempts!'
|
|
};
|
|
}
|
|
};
|
|
export const verifyToken = (twoFAToken) => !!(common.appConfig.secret2FA && common.appConfig.secret2FA !== '' && otplib.authenticator.check(twoFAToken, common.appConfig.secret2FA));
|
|
// Mirrors isAuthenticated: a request carrying a valid session JWT has already
|
|
// completed 2FA at login, since tokens are only minted after verification when
|
|
// 2FA is enabled. Used to exempt in-app re-authorization (e.g. the password
|
|
// prompt before on-chain sends) from the TOTP requirement without opening a
|
|
// password-only path.
|
|
const hasValidAuthToken = (req) => {
|
|
try {
|
|
const token = req.headers.authorization.split(' ')[1];
|
|
jwt.verify(token, common.secret_key);
|
|
return true;
|
|
}
|
|
catch (error) {
|
|
return false;
|
|
}
|
|
};
|
|
export const authenticateUser = (req, res, next) => {
|
|
const { authenticateWith, authenticationValue, twoFAToken } = req.body;
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'Authenticating User..' });
|
|
if (!!common.appConfig.disableAuth) {
|
|
if (!req.session.selectedNode) {
|
|
req.session.selectedNode = common.selectedNode;
|
|
}
|
|
const token = jwt.sign({ user: 'AUTH_DISABLED_USER' }, common.secret_key);
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'User Disabled Authentication' });
|
|
res.status(200).json({ token: token });
|
|
}
|
|
else if (+common.appConfig.SSO.rtlSSO) {
|
|
if (authenticateWith === 'JWT' && jwt.verify(authenticationValue, common.secret_key)) {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'User Authenticated' });
|
|
res.status(406).json({ message: 'SSO Authentication Error', error: 'Login with Password is not allowed with SSO.' });
|
|
}
|
|
else if (authenticateWith === 'PASSWORD') {
|
|
if (common.appConfig.SSO.cookieValue.trim().length >= 32 && crypto.timingSafeEqual(Buffer.from(crypto.createHash('sha256').update(common.appConfig.SSO.cookieValue).digest('hex'), 'utf-8'), Buffer.from(authenticationValue, 'utf-8'))) {
|
|
common.refreshCookie();
|
|
if (!req.session.selectedNode) {
|
|
req.session.selectedNode = common.selectedNode;
|
|
}
|
|
const token = jwt.sign({ user: 'SSO_USER' }, common.secret_key);
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'User Authenticated' });
|
|
res.status(200).json({ token: token });
|
|
}
|
|
else {
|
|
const errMsg = 'SSO Authentication Failed! Access key too short or does not match.';
|
|
const err = common.handleError({ statusCode: 406, message: 'SSO Authentication Error', error: errMsg }, 'Authenticate', errMsg, req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
const currentTime = new Date().getTime();
|
|
const reqIP = common.getRequestIP(req);
|
|
const failed = getFailedInfo(reqIP, currentTime);
|
|
const password = authenticationValue;
|
|
if (common.appConfig.rtlPass === password && failed.count < ALLOWED_LOGIN_ATTEMPTS) {
|
|
// Gate on the server-side 2FA configuration, not on the request: when 2FA is
|
|
// enabled a token is mandatory, so a request omitting twoFAToken is rejected
|
|
// instead of silently skipping verification. The login UI keys its token prompt
|
|
// on enable2FA, so both fields are consulted — a stale secret with 2FA disabled
|
|
// must not lock the operator out of a UI that never prompts for a token.
|
|
// Requests with a valid session token (in-app re-authorization, e.g. the
|
|
// password prompt before on-chain sends) are exempt from the TOTP requirement.
|
|
if (common.appConfig.enable2FA && common.appConfig.secret2FA && common.appConfig.secret2FA !== '' && !hasValidAuthToken(req)) {
|
|
if (typeof twoFAToken !== 'string' || twoFAToken === '' || !verifyToken(twoFAToken)) {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'ERROR', fileName: 'Authenticate', msg: 'Invalid Token! Failed IP ' + reqIP, error: { error: 'Invalid token.' } });
|
|
failed.count = failed.count + 1;
|
|
failed.lastTried = currentTime;
|
|
return res.status(401).json(handleMultipleFailedAttemptsError(failed, currentTime, 'Invalid 2FA Token!'));
|
|
}
|
|
}
|
|
if (!req.session.selectedNode) {
|
|
req.session.selectedNode = common.selectedNode;
|
|
}
|
|
delete failedLoginAttempts[reqIP];
|
|
const token = jwt.sign({ user: 'NODE_USER' }, common.secret_key);
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'User Authenticated' });
|
|
res.status(200).json({ token: token });
|
|
}
|
|
else {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'ERROR', fileName: 'Authenticate', msg: 'Invalid Password! Failed IP ' + reqIP, error: { error: 'Invalid password.' } });
|
|
failed.count = common.appConfig.rtlPass !== password ? (failed.count + 1) : failed.count;
|
|
failed.lastTried = common.appConfig.rtlPass !== password ? currentTime : failed.lastTried;
|
|
return res.status(401).json(handleMultipleFailedAttemptsError(failed, currentTime, 'Invalid Password!'));
|
|
}
|
|
}
|
|
};
|
|
export const resetPassword = (req, res, next) => {
|
|
const { currPassword, newPassword } = req.body;
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'Resetting Password..' });
|
|
if (+common.appConfig.SSO.rtlSSO) {
|
|
const errMsg = 'Password cannot be reset for SSO authentication';
|
|
const err = common.handleError({ statusCode: 401, message: 'Password Reset Error', error: errMsg }, 'Authenticate', errMsg, req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
}
|
|
else {
|
|
if (common.appConfig.rtlPass === currPassword) {
|
|
common.appConfig.rtlPass = common.replacePasswordWithHash(newPassword);
|
|
const token = jwt.sign({ user: 'NODE_USER' }, common.secret_key);
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'Password Reset Successful' });
|
|
res.status(200).json({ token: token });
|
|
}
|
|
else {
|
|
const errMsg = 'Incorrect Old Password';
|
|
const err = common.handleError({ statusCode: 401, message: 'Password Reset Error', error: errMsg }, 'Authenticate', errMsg, req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
}
|
|
}
|
|
};
|
|
export const logoutUser = (req, res, next) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'Logged out' });
|
|
if (req.session.selectedNode && req.session.selectedNode.index) {
|
|
databaseService.unloadDatabase(+req.session.selectedNode.index, req.session.id);
|
|
}
|
|
req.session.destroy((err) => {
|
|
res.clearCookie('connect.sid');
|
|
res.status(200).json({ loggedout: true });
|
|
});
|
|
};
|