Conversation
|
|
||
| balance, err := client.AccountAPTBalance(addr) | ||
| if err != nil { | ||
| s.logger.Warnw("failed to get balance for account, skipping", "account", account, "address", addr.String(), "error", err) |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 3 hours ago
In general, to fix clear-text logging of sensitive information, you should avoid logging the sensitive value or, if logging is necessary, log only a redacted or truncated form that cannot be used maliciously (e.g., masking most characters, hashing, or omitting it entirely). The functional behavior of the code (business logic) should remain unchanged; only what is emitted to logs should be adjusted.
For this specific case, the problematic sink is the Warnw call in getAccountWithHighestBalance on line 308 of relayer/aptos_service.go:
s.logger.Warnw("failed to get balance for account, skipping", "account", account, "address", addr.String(), "error", err)We can fix this by:
- Removing the
"address", addr.String()field entirely (relying on"account", accountfor context), or - Replacing it with a redacted form that does not expose the full address.
To preserve debuggability while aligning with the rule, the best minimal-impact change is to log only a truncated version of the address (e.g., first and last few characters) that cannot be used directly as an identifier but is still useful for correlating events. Since we cannot change imports beyond standard libraries and must not modify code outside the shown snippet, we will compute this redacted string inline in the log call.
Concretely:
- Edit
relayer/aptos_service.goinsidegetAccountWithHighestBalance. - Replace the
Warnwinvocation on line 308 with one that logs a redacted address usingaddr.String()locally, e.g., keeping only the first 6 and last 4 characters and replacing the middle with"...". - No changes are needed in
relayer/utils/address.go.
| @@ -305,7 +305,11 @@ | ||
|
|
||
| balance, err := client.AccountAPTBalance(addr) | ||
| if err != nil { | ||
| s.logger.Warnw("failed to get balance for account, skipping", "account", account, "address", addr.String(), "error", err) | ||
| addrStr := addr.String() | ||
| if len(addrStr) > 10 { | ||
| addrStr = addrStr[:6] + "..." + addrStr[len(addrStr)-4:] | ||
| } | ||
| s.logger.Warnw("failed to get balance for account, skipping", "account", account, "redactedAddress", addrStr, "error", err) | ||
| continue | ||
| } | ||
|
|
|
|
||
| acc := utils.Ed25519PublicKeyToAddress(ed25519PublicKey) | ||
| fromAddress := acc.String() | ||
| a.baseLogger.Infow("TestingAptosWriteCap: EnqueueCRE - resolved from address", "fromAddress", fromAddress) |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 hours ago
General approach: Avoid logging the full value derived from the authKey (fromAddress). Either omit it entirely from logs or log only a redacted/partial version that is not considered sensitive under your policy, while preserving all existing functional behavior of the transaction creation and sending logic.
Best concrete fix here: Keep using the full fromAddress for constructing fromAccountAddress and the AptosTx, but change the logging call so that it does not emit the complete address. A common pattern is to log only a prefix/suffix of the address (e.g., first 6 and last 4 characters) and indicate that it is redacted. To implement this in a minimal, contained way:
- In
relayer/txm/txm.go, just before logging, derive a redacted string fromfromAddress(e.g.,utils.RedactAddress(fromAddress)or, since we cannot modifyutilsbeyond what’s shown, implement a small local helper inline in this file). - Replace the logging argument
"fromAddress", fromAddresswith"fromAddress", redactedFromAddress. - Do not change how
fromAddressis used forParseStringRelaxedor in theAptosTxstruct.
Since we are constrained to only edit the shown snippets and two files, the simplest is to add a small helper function in relayer/txm/txm.go (e.g., redactAddressString) and use that in the Infow and Errorw where the address appears. This maintains functionality and improves privacy.
Concretely:
-
In
relayer/txm/txm.go, define a helper like:func redactAddressString(addr string) string { if len(addr) <= 10 { return "REDACTED" } return addr[:6] + "..." + addr[len(addr)-4:] }
-
Use
redactAddressString(fromAddress)in theInfowandErrorwcalls that log"fromAddress".
No new imports are required.
| @@ -27,6 +27,14 @@ | ||
|
|
||
| var _ services.Service = &AptosTxm{} | ||
|
|
||
| func redactAddressString(addr string) string { | ||
| if len(addr) <= 10 { | ||
| // Avoid leaking very short addresses; replace entirely. | ||
| return "REDACTED" | ||
| } | ||
| return addr[:6] + "..." + addr[len(addr)-4:] | ||
| } | ||
|
|
||
| type AptosTxm struct { | ||
| baseLogger logger.Logger | ||
| keystore loop.Keystore | ||
| @@ -278,12 +286,13 @@ | ||
|
|
||
| acc := utils.Ed25519PublicKeyToAddress(ed25519PublicKey) | ||
| fromAddress := acc.String() | ||
| a.baseLogger.Infow("TestingAptosWriteCap: EnqueueCRE - resolved from address", "fromAddress", fromAddress) | ||
| redactedFromAddress := redactAddressString(fromAddress) | ||
| a.baseLogger.Infow("TestingAptosWriteCap: EnqueueCRE - resolved from address", "fromAddress", redactedFromAddress) | ||
|
|
||
| fromAccountAddress := &aptos.AccountAddress{} | ||
| err = fromAccountAddress.ParseStringRelaxed(fromAddress) | ||
| if err != nil { | ||
| a.baseLogger.Errorw("TestingAptosWriteCap: EnqueueCRE - failed to parse from address", "fromAddress", fromAddress, "error", err) | ||
| a.baseLogger.Errorw("TestingAptosWriteCap: EnqueueCRE - failed to parse from address", "fromAddress", redactedFromAddress, "error", err) | ||
| return fmt.Errorf("failed to parse from address: %+w", err) | ||
| } | ||
|
|
| fromAccountAddress := &aptos.AccountAddress{} | ||
| err = fromAccountAddress.ParseStringRelaxed(fromAddress) | ||
| if err != nil { | ||
| a.baseLogger.Errorw("TestingAptosWriteCap: EnqueueCRE - failed to parse from address", "fromAddress", fromAddress, "error", err) |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 hours ago
In general, to fix clear-text logging of sensitive information, remove the sensitive value from log messages, or replace it with a redacted/hashed/shortened form that is safe to expose. The functional behavior of the code (business logic, return values, etc.) should remain unchanged; only what is emitted to logs should change. If the value is only needed for debugging, consider logging a non-reversible fingerprint (e.g., hash, truncated form) instead of the full value.
In this specific case, the problematic logging occurs in relayer/txm/txm.go at the error log:
a.baseLogger.Errorw("TestingAptosWriteCap: EnqueueCRE - failed to parse from address", "fromAddress", fromAddress, "error", err)We should avoid logging fromAddress in clear text. The simplest change that preserves functionality is to remove "fromAddress", fromAddress from this log line. The address is not needed to continue the logic (the function is returning an error immediately after logging), and the error itself already describes what failed. If we still want some context, we could replace it with a redacted version (e.g., the last few characters), but that introduces extra code and still may be considered sensitive. Given the instructions to avoid logging sensitive data, the safest fix is to drop the address from the log entry altogether.
No additional imports or helper methods are required. Only the single Errorw call in relayer/txm/txm.go around line 286 needs to be updated.
| @@ -283,7 +283,7 @@ | ||
| fromAccountAddress := &aptos.AccountAddress{} | ||
| err = fromAccountAddress.ParseStringRelaxed(fromAddress) | ||
| if err != nil { | ||
| a.baseLogger.Errorw("TestingAptosWriteCap: EnqueueCRE - failed to parse from address", "fromAddress", fromAddress, "error", err) | ||
| a.baseLogger.Errorw("TestingAptosWriteCap: EnqueueCRE - failed to parse from address", "error", err) | ||
| return fmt.Errorf("failed to parse from address: %+w", err) | ||
| } | ||
|
|
|
|
||
| select { | ||
| case a.broadcastChan <- transactionID: | ||
| ctxLogger.Infow("TestingAptosWriteCap: EnqueueCRE - tx enqueued to broadcast channel", "fromAddr", fromAddress, "transactionID", transactionID) |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 hours ago
To fix this, we should stop logging the full fromAddress value in clear text, and instead log a safely derived representation (for example, a truncated form that keeps only a small prefix/suffix, or a hash) that still allows operators to correlate log entries without exposing the complete address. This preserves functionality (transaction enqueueing, parsing, broadcasting) while removing the sensitive value from logs.
The minimal, targeted change is in relayer/txm/txm.go:
- Introduce a small helper in this file that redacts an address string for logging, e.g. returning
"***"on empty input and otherwise<first 6>...<last 4>. This is purely local to logging and does not change any business logic. - Change the two logging calls that currently log
fromAddress:- The
Infowcall at line 281:"resolved from address", "fromAddress", fromAddress. - The
Infowcall at line 325:"fromAddr", fromAddress.
Replace the logged value with a redacted form, e.g.redactAddressForLog(fromAddress).
- The
- No external dependencies are needed; we only add one small helper function in the same file.
No changes are required in relayer/utils/address.go because the computation of the address is correct and only the logging is problematic.
| @@ -27,6 +27,19 @@ | ||
|
|
||
| var _ services.Service = &AptosTxm{} | ||
|
|
||
| // redactAddressForLog returns a redacted representation of an account address | ||
| // suitable for logging without exposing the full value. | ||
| func redactAddressForLog(addr string) string { | ||
| if len(addr) == 0 { | ||
| return "" | ||
| } | ||
| // If the address is very short, avoid panics and just return a fixed mask. | ||
| if len(addr) <= 10 { | ||
| return "***" | ||
| } | ||
| // Keep a small prefix and suffix to aid debugging while redacting the rest. | ||
| return addr[:6] + "..." + addr[len(addr)-4:] | ||
| } | ||
| type AptosTxm struct { | ||
| baseLogger logger.Logger | ||
| keystore loop.Keystore | ||
| @@ -278,7 +291,7 @@ | ||
|
|
||
| acc := utils.Ed25519PublicKeyToAddress(ed25519PublicKey) | ||
| fromAddress := acc.String() | ||
| a.baseLogger.Infow("TestingAptosWriteCap: EnqueueCRE - resolved from address", "fromAddress", fromAddress) | ||
| a.baseLogger.Infow("TestingAptosWriteCap: EnqueueCRE - resolved from address", "fromAddress", redactAddressForLog(fromAddress)) | ||
|
|
||
| fromAccountAddress := &aptos.AccountAddress{} | ||
| err = fromAccountAddress.ParseStringRelaxed(fromAddress) | ||
| @@ -322,7 +335,7 @@ | ||
|
|
||
| select { | ||
| case a.broadcastChan <- transactionID: | ||
| ctxLogger.Infow("TestingAptosWriteCap: EnqueueCRE - tx enqueued to broadcast channel", "fromAddr", fromAddress, "transactionID", transactionID) | ||
| ctxLogger.Infow("TestingAptosWriteCap: EnqueueCRE - tx enqueued to broadcast channel", "fromAddr", redactAddressForLog(fromAddress), "transactionID", transactionID) | ||
| default: | ||
| // if the channel is full, we drop the transaction. | ||
| // we do this instead of setting the tx in `a.transactions` post-broadcast to avoid a race |
| lggr logger.Logger | ||
| ds sqlutil.DataSource | ||
| keyStore loop.Keystore | ||
|
|
There was a problem hiding this comment.
passing in keystore to use the highest balance transmitter account.
Check aptos_service.SubmitTransaction
TODO:
smartcontractkit/chainlink#21431