@@ -72,8 +72,14 @@ class RateLimitedProvider extends ethers.providers.StaticJsonRpcProvider {
72
72
73
73
const defaultTimeout = 60 * 1000 ;
74
74
75
+ // @dev To avoid accidentally leaking RPC keys in log messages, resolve the RPC provider protocol and
76
+ // hostname centrally. There should be no instances of `provider.connection.url` in log messages or errors.
77
+ function getProviderOrigin ( provider : ethers . providers . StaticJsonRpcProvider ) : string {
78
+ return getOriginFromURL ( provider . connection . url ) ;
79
+ }
80
+
75
81
function formatProviderError ( provider : ethers . providers . StaticJsonRpcProvider , rawErrorText : string ) {
76
- return `Provider ${ getOriginFromURL ( provider . connection . url ) } failed with error: ${ rawErrorText } ` ;
82
+ return `Provider ${ getProviderOrigin ( provider ) } failed with error: ${ rawErrorText } ` ;
77
83
}
78
84
79
85
function createSendErrorWithMessage ( message : string , sendError : any ) {
@@ -127,6 +133,8 @@ class CacheProvider extends RateLimitedProvider {
127
133
this . maxReorgDistance = CHAIN_CACHE_FOLLOW_DISTANCE [ chainId ] ;
128
134
129
135
// Pre-compute as much of the redis key as possible.
136
+ // The full provider URL is deliberately used here, since the redis cache is considered sensitive,
137
+ // but additional caution is needed to ensure the cache prefix is not logged anywhere.
130
138
const cachePrefix = `${ providerCacheNamespace } ,${ new URL ( this . connection . url ) . hostname } ,${ chainId } ` ;
131
139
this . getBlockByNumberPrefix = `${ cachePrefix } :getBlockByNumber,` ;
132
140
this . getLogsCachePrefix = `${ cachePrefix } :eth_getLogs,` ;
@@ -306,7 +314,9 @@ export class RetryProvider extends ethers.providers.StaticJsonRpcProvider {
306
314
if ( ! results . every ( isPromiseFulfilled ) ) {
307
315
// Format the error so that it's very clear which providers failed and succeeded.
308
316
const errorTexts = errors . map ( ( [ provider , errorText ] ) => formatProviderError ( provider , errorText ) ) ;
309
- const successfulProviderUrls = results . filter ( isPromiseFulfilled ) . map ( ( result ) => result . value [ 0 ] . connection . url ) ;
317
+ const successfulProviderUrls = results
318
+ . filter ( isPromiseFulfilled )
319
+ . map ( ( result ) => resolveProviderOrigin ( result . value [ 0 ] ) ) ;
310
320
throw createSendErrorWithMessage (
311
321
`Not enough providers succeeded. Errors:\n${ errorTexts . join ( "\n" ) } \n` +
312
322
`Successful Providers:\n${ successfulProviderUrls . join ( "\n" ) } ` ,
@@ -324,13 +334,13 @@ export class RetryProvider extends ethers.providers.StaticJsonRpcProvider {
324
334
325
335
const throwQuorumError = ( ) => {
326
336
const errorTexts = errors . map ( ( [ provider , errorText ] ) => formatProviderError ( provider , errorText ) ) ;
327
- const successfulProviderUrls = values . map ( ( [ provider ] ) => provider . connection . url ) ;
337
+ const successfulProviderUrls = values . map ( ( [ provider ] ) => resolveProviderOrigin ( provider ) ) ;
328
338
throw new Error (
329
339
"Not enough providers agreed to meet quorum.\n" +
330
340
"Providers that errored:\n" +
331
341
`${ errorTexts . join ( "\n" ) } \n` +
332
342
"Providers that succeeded, but some failed to match:\n" +
333
- successfulProviderUrls . join ( "\n" )
343
+ successfulProviderUrls . map ( ( url ) => getOriginFromURL ( url ) ) . join ( "\n" )
334
344
) ;
335
345
} ;
336
346
@@ -390,11 +400,11 @@ export class RetryProvider extends ethers.providers.StaticJsonRpcProvider {
390
400
const mismatchedProviders = Object . fromEntries (
391
401
[ ...values , ...fallbackValues ]
392
402
. filter ( ( [ , result ] ) => ! compareRpcResults ( method , result , quorumResult ) )
393
- . map ( ( [ provider , result ] ) => [ provider . connection . url , result ] )
403
+ . map ( ( [ provider , result ] ) => [ getProviderOrigin ( provider ) , result ] )
394
404
) ;
395
405
const quorumProviders = [ ...values , ...fallbackValues ]
396
406
. filter ( ( [ , result ] ) => compareRpcResults ( method , result , quorumResult ) )
397
- . map ( ( [ provider ] ) => provider . connection . url ) ;
407
+ . map ( ( [ provider ] ) => getProviderOrigin ( provider ) ) ;
398
408
if ( Object . keys ( mismatchedProviders ) . length > 0 || errors . length > 0 ) {
399
409
logger . warn ( {
400
410
at : "ProviderUtils" ,
0 commit comments