Skip to content

feat(logger): enhance sanitize to handle Date, BigInt, and string types and add the test file.Reduce the depth from 50 to 25.#8231

Open
rishikeshdadam136 wants to merge 1 commit intomasterfrom
WP-8110
Open

feat(logger): enhance sanitize to handle Date, BigInt, and string types and add the test file.Reduce the depth from 50 to 25.#8231
rishikeshdadam136 wants to merge 1 commit intomasterfrom
WP-8110

Conversation

@rishikeshdadam136
Copy link
Contributor

@rishikeshdadam136 rishikeshdadam136 commented Mar 3, 2026

TICKET-8110

The sanitize() function in @bitgo/logger handles the below ones correctly and added the test files.

  • Date objects.
  • BigInt values.
  • Strings — bearer v2 tokens passed as top-level strings are not redacted.
    -Reduce the depth.

@rishikeshdadam136
Copy link
Contributor Author

@copilot Review it as 10x engineer.

Copy link

Copilot AI commented Mar 3, 2026

@rishikeshdadam136 I've opened a new pull request, #8232, to work on those changes. Once the pull request is ready, I'll request review from you.

@rishikeshdadam136
Copy link
Contributor Author

@claude review it as 10x engineer

@rishikeshdadam136 rishikeshdadam136 marked this pull request as ready for review March 3, 2026 13:46
@rishikeshdadam136 rishikeshdadam136 requested review from a team as code owners March 3, 2026 13:46
}

if (typeof obj === 'string') {
return isBearerV2Token(obj) ? '<REMOVED>' : obj;
Copy link
Contributor

Choose a reason for hiding this comment

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

why only bearerV2? shouldn't we remove all sensitive fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it has a recognizable format (v2x + hex) that can be detected from the string content alone. For other sensitive values (passwords, private keys, etc.), we can only identify them when they appear under a sensitive key name, which is already handled in the object iteration loop.
if u suggest me any particular format like bearer i will add that also.
Thank you.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see

xprv is a pattern that we detect as a prefix as well

Copy link
Contributor

Choose a reason for hiding this comment

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

add a function isSensitiveStringValue(s: string) that does the v2x and xprv prefix checks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will look into it
Very Thanks

}

if (typeof obj === 'string') {
return isBearerV2Token(obj) ? '<REMOVED>' : obj;
Copy link
Contributor

Choose a reason for hiding this comment

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

add a function isSensitiveStringValue(s: string) that does the v2x and xprv prefix checks

@dsobkowi dsobkowi removed the request for review from a team March 3, 2026 17:28

// Handle Date objects
if (obj instanceof Date) {
return obj.toISOString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return obj.toISOString();
return isNaN(obj.getTime()) ? '[Invalid Date]' : obj.toISOString();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will look into it.

]);

const BEARER_V2_PATTERN = /^v2x[a-f0-9]{32,}$/i;
const SENSITIVE_PREFIXES = ['v2x', 'xprv'];
Copy link
Contributor

Choose a reason for hiding this comment

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

The old implementation used a case-insensitive regex , so tokens like V2Xaabb... were caught. The new startsWith('v2x') check is case-sensitive, so mixed-case tokens will slip through unredacted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes will slip through but normally the tokens in the logging statements will be in this format(v2xaabb..) only right,i mean no capital alphabet.

@sachushaji
Copy link
Contributor

@claude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants