Skip to content

Potential fix for code scanning alert no. 155: Clear text storage of sensitive information#53

Merged
Mostafa-SAID7 merged 1 commit into
mainfrom
alert-autofix-155
Jun 7, 2026
Merged

Potential fix for code scanning alert no. 155: Clear text storage of sensitive information#53
Mostafa-SAID7 merged 1 commit into
mainfrom
alert-autofix-155

Conversation

@Mostafa-SAID7

@Mostafa-SAID7 Mostafa-SAID7 commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/Mostafa-SAID7/Bank-Api/security/code-scanning/155

General fix: do not log full sensitive identifiers; instead log a masked/tokenized representation (or encrypted value where appropriate). For this file, the least disruptive fix is to mask accountId before writing to logs/audit messages.

Best single fix in src/Bank.Application/Services/Shared/InterestCalculationService.cs:

  1. Add a private helper method to mask GUIDs (e.g., keep first 8 chars, mask the rest).
  2. In UpdateInterestRateAsync, compute maskedAccountId once near where accountId is used for messaging.
  3. Replace clear-text accountId usages in:
    • line 287 audit log message string interpolation
    • line 288/289 informational log parameters
    • line 270 warning log
    • line 276 warning log
    • line 295 error log
      so only masked value is persisted in logs.
  4. Keep repository lookup unchanged (GetByIdAsync(accountId)) to preserve functionality.

No new dependency is required.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Summary by CodeRabbit

Release Notes

  • Security
    • Account identifiers are now masked in application logs to protect sensitive information.

…sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7d0206e2-fe62-4d7a-bd21-0770fb4788b5

📥 Commits

Reviewing files that changed from the base of the PR and between 9b01749 and 4b5663f.

📒 Files selected for processing (1)
  • src/Bank.Application/Services/Shared/InterestCalculationService.cs

📝 Walkthrough

Walkthrough

The PR modifies the interest calculation service to mask account identifiers in logs. The UpdateInterestRateAsync method now computes a masked GUID string and uses it in all warning, information, and error log messages instead of exposing the raw account ID.

Changes

Account ID Masking

Layer / File(s) Summary
Account ID Masking in Interest Rate Updates
src/Bank.Application/Services/Shared/InterestCalculationService.cs
The UpdateInterestRateAsync method masks the accountId parameter and applies it to account-not-found and invalid-rate warnings, audit logs, info logs, and error logs. A new MaskGuid(Guid id) helper converts the GUID to "N" format and returns either a fixed mask or the first 8 characters plus a mask suffix.

🎯 2 (Simple) | ⏱️ ~8 minutes

🐰 Small change, quite sane,
Masking IDs in logs today,
No secrets in the rain,
Just asterisks at play,
Safety hops the way!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch alert-autofix-155

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Mostafa-SAID7
Mostafa-SAID7 marked this pull request as ready for review June 7, 2026 05:29
@Mostafa-SAID7
Mostafa-SAID7 merged commit 78c7747 into main Jun 7, 2026
8 of 9 checks passed

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@sonarqubecloud

sonarqubecloud Bot commented Jun 7, 2026

Copy link
Copy Markdown

@sonarqubecloud

sonarqubecloud Bot commented Jun 7, 2026

Copy link
Copy Markdown

if (account == null)
{
_logger.LogWarning("Account {AccountId} not found for interest rate update", accountId);
_logger.LogWarning("Account {AccountId} not found for interest rate update", maskedAccountId);
if (newRate < 0 || newRate > 10) // Reasonable bounds
{
_logger.LogWarning("Invalid interest rate {Rate} for account {AccountId}", newRate, accountId);
_logger.LogWarning("Invalid interest rate {Rate} for account {AccountId}", newRate, maskedAccountId);
$"Interest rate for account {maskedAccountId} updated from {oldRate}% to {newRate}%", userId);
_logger.LogInformation("Interest rate for account {AccountId} updated from {OldRate}% to {NewRate}%",
accountId, oldRate, newRate);
maskedAccountId, oldRate, newRate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants