Skip to content

Commit dcad519

Browse files
committed
Additional instances
1 parent 7939670 commit dcad519

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/utils/ProviderUtils.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ class RateLimitedProvider extends ethers.providers.StaticJsonRpcProvider {
7272

7373
const defaultTimeout = 60 * 1000;
7474

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+
7581
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}`;
7783
}
7884

7985
function createSendErrorWithMessage(message: string, sendError: any) {
@@ -127,6 +133,8 @@ class CacheProvider extends RateLimitedProvider {
127133
this.maxReorgDistance = CHAIN_CACHE_FOLLOW_DISTANCE[chainId];
128134

129135
// 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.
130138
const cachePrefix = `${providerCacheNamespace},${new URL(this.connection.url).hostname},${chainId}`;
131139
this.getBlockByNumberPrefix = `${cachePrefix}:getBlockByNumber,`;
132140
this.getLogsCachePrefix = `${cachePrefix}:eth_getLogs,`;
@@ -306,7 +314,9 @@ export class RetryProvider extends ethers.providers.StaticJsonRpcProvider {
306314
if (!results.every(isPromiseFulfilled)) {
307315
// Format the error so that it's very clear which providers failed and succeeded.
308316
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]));
310320
throw createSendErrorWithMessage(
311321
`Not enough providers succeeded. Errors:\n${errorTexts.join("\n")}\n` +
312322
`Successful Providers:\n${successfulProviderUrls.join("\n")}`,
@@ -324,13 +334,13 @@ export class RetryProvider extends ethers.providers.StaticJsonRpcProvider {
324334

325335
const throwQuorumError = () => {
326336
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));
328338
throw new Error(
329339
"Not enough providers agreed to meet quorum.\n" +
330340
"Providers that errored:\n" +
331341
`${errorTexts.join("\n")}\n` +
332342
"Providers that succeeded, but some failed to match:\n" +
333-
successfulProviderUrls.join("\n")
343+
successfulProviderUrls.map((url) => getOriginFromURL(url)).join("\n")
334344
);
335345
};
336346

@@ -390,11 +400,11 @@ export class RetryProvider extends ethers.providers.StaticJsonRpcProvider {
390400
const mismatchedProviders = Object.fromEntries(
391401
[...values, ...fallbackValues]
392402
.filter(([, result]) => !compareRpcResults(method, result, quorumResult))
393-
.map(([provider, result]) => [provider.connection.url, result])
403+
.map(([provider, result]) => [getProviderOrigin(provider), result])
394404
);
395405
const quorumProviders = [...values, ...fallbackValues]
396406
.filter(([, result]) => compareRpcResults(method, result, quorumResult))
397-
.map(([provider]) => provider.connection.url);
407+
.map(([provider]) => getProviderOrigin(provider));
398408
if (Object.keys(mismatchedProviders).length > 0 || errors.length > 0) {
399409
logger.warn({
400410
at: "ProviderUtils",

0 commit comments

Comments
 (0)