Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mask BlockDaemon RPC endpoints in logs #191

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions relayer/middleware/providers.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ export function providers(

const chains = Object.assign({}, defaultChains, opts?.chains);

logger?.debug(`Providers initializing... ${JSON.stringify(chains)}`);
logger?.debug(
`Providers initializing... ${JSON.stringify(maskRPCProviders(chains))}`,
);
providers = await buildProviders(chains, logger);
logger?.debug(`Providers initialized succesfully.`);
}
Expand Down Expand Up @@ -260,7 +262,9 @@ async function buildProviders(
error.originalStack = error.stack;
error.stack = new Error().stack;
logger?.error(
`Failed to initialize provider for chain: ${chainIdStr} - endpoints: ${endpoints}. Error: `,
`Failed to initialize provider for chain: ${chainIdStr} - endpoints: ${maskRPCEndpoints(
endpoints,
)}. Error: `,
error,
);
throw error;
Expand All @@ -269,3 +273,24 @@ async function buildProviders(

return providers;
}

function maskRPCEndpoints(endpoints: string[]) {
return endpoints.map((url: string) => {
const apiKeyPos = url.indexOf("apiKey");
if (apiKeyPos > -1) {
// Found API key in the RPC url, show only initial 3 chars and mask the rest
return url.substring(0, apiKeyPos + 10) + "***";
}
return url;
});
}

function maskRPCProviders(chains: Partial<ChainConfigInfo>) {
const maskedChains: Partial<ChainConfigInfo> = {};
for (const [chainId, chainConfig] of Object.entries(chains)) {
maskedChains[chainId as unknown as ChainId] = {
endpoints: maskRPCEndpoints(chainConfig.endpoints),
};
}
return maskedChains;
}