Replace deprecated request/request-promise with axios
request has been deprecated since 2020 with an unfixed SSRF advisory and
pins vulnerable copies of form-data (critical), qs, tough-cookie and
uuid - 8 of the 13 remaining production audit findings, none fixable by
version bumps (issue #1634, item 1).
All 36 backend files that imported request-promise now use a small
compatibility wrapper (server/utils/request.ts) backed by axios, which
is already a production dependency. The wrapper accepts the existing
options shape (qs, form - object or pre-encoded string, body,
baseUrl/uri, rejectUnauthorized, json), resolves with the response body
directly, and rejects with a plain object mirroring request-promise's
StatusCodeError/RequestError shape, so CommonService.handleError works
unchanged (ECONNREFUSED -> 503, Eclair StatusCodeError -> 500, nested
error body extraction). Auth headers are excluded from rejected errors
so they cannot leak into logs. Callers without json: true (block
explorer, currency rates) still get raw text bodies, and LND's
line-delimited /v2/router/send stream still surfaces as a string for
the existing parser.
Only behavioral code change: CLN verifyMessage used request-promise's
callback style and was ported to the same promise style as signMessage;
four Eclair handlers gained explicit returns to satisfy
noImplicitReturns once the import became typed.
Production npm audit drops from 13 findings (2 critical) to 6 low, all
in the crypto-browserify/elliptic chain tracked in #1634.
Verified against the docker regtest fixture with 43 API checks across
LND, Core Lightning and Eclair: reads, invoice creation, a routed LND
payment over the streaming endpoint, cross-implementation payments from
CLN and Eclair, message sign/verify, channel backup to disk, and
bad-invoice/node-unreachable error mapping. Lint and both production
builds are clean.
2026-07-19 12:08:05 -07:00
import request from '../../utils/request.js' ;
2021-12-29 18:08:41 -05:00
import { Logger , LoggerService } from '../../utils/logger.js' ;
import { Common , CommonService } from '../../utils/common.js' ;
let options = null ;
const logger : LoggerService = Logger ;
const common : CommonService = Common ;
2022-05-01 13:35:20 -04:00
const responseData = { switch : { forwarding_events : [ ] , last_offset_index : 0 } , fees : { forwarding_events : [ ] , last_offset_index : 0 } } ;
2021-12-29 18:08:41 -05:00
const num_max_events = 100 ;
export const forwardingHistory = ( req , res , next ) = > {
2024-06-10 12:40:37 -07:00
const { start_time , end_time } = req . body ;
getAllForwardingEvents ( req , start_time , end_time , 0 , 'switch' , ( eventsResponse ) = > {
2021-12-29 18:08:41 -05:00
if ( eventsResponse . error ) {
res . status ( eventsResponse . error . statusCode ) . json ( eventsResponse ) ;
} else {
res . status ( 201 ) . json ( eventsResponse ) ;
}
} ) ;
} ;
2022-05-01 13:35:20 -04:00
export const getAllForwardingEvents = ( req , start , end , offset , caller , callback ) = > {
2021-12-29 18:08:41 -05:00
logger . log ( { selectedNode : req.session.selectedNode , level : 'INFO' , fileName : 'Switch' , msg : 'Getting Forwarding Events..' } ) ;
2022-05-01 13:35:20 -04:00
if ( offset === 0 ) { responseData [ caller ] = { forwarding_events : [ ] , last_offset_index : 0 } ; }
2021-12-29 18:08:41 -05:00
if ( ! req . session . selectedNode ) {
const err = common . handleError ( { message : 'Session Expired after a day\'s inactivity.' , statusCode : 401 } , 'Balance' , 'Get Balance Error' , req . session . selectedNode ) ;
return callback ( { message : err.message , error : err.error , statusCode : err.statusCode } ) ;
} options = common . getOptions ( req ) ;
2024-06-10 12:40:37 -07:00
options . url = req . session . selectedNode . settings . lnServerUrl + '/v1/switch' ;
2021-12-29 18:08:41 -05:00
options . form = { } ;
if ( start ) { options . form . start_time = start ; }
if ( end ) { options . form . end_time = end ; }
options . form . num_max_events = num_max_events ;
options . form . index_offset = offset ;
options . form = JSON . stringify ( options . form ) ;
2022-01-16 15:55:50 -05:00
logger . log ( { selectedNode : req.session.selectedNode , level : 'DEBUG' , fileName : 'Switch' , msg : 'Forwarding Events Params' , data : options.form } ) ;
2021-12-29 18:08:41 -05:00
return request . post ( options ) . then ( ( body ) = > {
2022-01-16 15:55:50 -05:00
logger . log ( { selectedNode : req.session.selectedNode , level : 'INFO' , fileName : 'Switch' , msg : 'Forwarding Events Received' , data : body } ) ;
2021-12-29 18:08:41 -05:00
if ( body . forwarding_events ) {
2022-05-01 13:35:20 -04:00
responseData [ caller ] . forwarding_events . push ( . . . body . forwarding_events ) ;
responseData [ caller ] . last_offset_index = body . last_offset_index ? body.last_offset_index : 0 ;
2021-12-29 18:08:41 -05:00
}
if ( ! body . last_offset_index || body . last_offset_index < offset + num_max_events ) {
2022-05-01 13:35:20 -04:00
responseData [ caller ] . last_offset_index = body . last_offset_index ? body.last_offset_index : 0 ;
return callback ( responseData [ caller ] ) ;
2021-12-29 18:08:41 -05:00
} else {
2022-05-01 13:35:20 -04:00
return getAllForwardingEvents ( req , start , end , offset + num_max_events , caller , callback ) ;
2021-12-29 18:08:41 -05:00
}
} ) . catch ( ( errRes ) = > {
const err = common . handleError ( errRes , 'Switch' , 'Get All Forwarding Events Error' , req . session . selectedNode ) ;
return callback ( { message : err.message , error : err.error , statusCode : err.statusCode } ) ;
} ) ;
} ;