-
Notifications
You must be signed in to change notification settings - Fork 15
Sanitize credential-like URLs in telemetry events to avoid False CredScan detection #340
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
Open
yashnap
wants to merge
16
commits into
master
Choose a base branch
from
37515045lpe-uri-credential-redaction
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f7be25e
Sanitize credential-like URLs in telemetry events
yashnap d685a52
Address Copilot Review comments
yashnap e88327a
Code coverage Fix
yashnap 281f3e0
Address CR comments.
yashnap ac91bd5
Remove unchanged file
yashnap 5861900
Address code review comments
yashnap e0edee2
Address Code Review
yashnap 292547e
fix UT coverage
yashnap 5e8f80f
Remove couple of tests that are repeatative
yashnap e489e9f
Convert few tests to UT's to fix code coverage
yashnap 20c6824
Coverage
yashnap 8d86f40
Address Code Review
yashnap 3ddb799
Code coverage fix
yashnap 5d433f3
Update RunTimeComposer to fix issue
yashnap 6d4140c
Revert "Code coverage fix"
yashnap 31746d9
Reverting back after extra file commit
yashnap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Copyright 2026 Microsoft Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # Requires Python 2.7+ | ||
| import re | ||
|
|
||
|
|
||
| class CredentialSanitizer(object): | ||
| """Service that sanitizes credential-like values from URIs by removing password/token from URI userinfo.""" | ||
|
|
||
| def __init__(self, composite_logger): | ||
| self.composite_logger = composite_logger | ||
|
|
||
| def sanitize(self, message): | ||
| """Removes password/token from URI credentials in the given message. | ||
| Args: | ||
| message: The message to sanitize | ||
| Returns: The message with credentials removed from URIs | ||
| """ | ||
| try: | ||
| # Pattern matches: scheme://user:password@host → scheme://user@host | ||
| # Handles credentials containing special characters (except @, /, whitespace) | ||
| # Groups: | ||
| # (1) scheme: https://, http://, or ftp:// | ||
| # (2) username: one or more non-whitespace, non-slash, non-colon, non-@ characters | ||
| # (3) password: zero or more non-whitespace, non-slash, non-@ characters | ||
| sanitized_message = re.sub(r'(https?://|ftp://)([^:/@\s]+):([^@/\s]*)@',r'\1\2@',message) | ||
| self.composite_logger.log_verbose("Message was sanitized to remove sensitive information. [InputMessage={0}][SanitizedMessage={1}]".format(str(message), str(sanitized_message))) | ||
| return sanitized_message | ||
| except Exception as error: | ||
| self.composite_logger.log_error("Error occurred while sanitizing credentials from message: [Error={0}]".format(repr(error))) | ||
| return message | ||
|
rane-rajasi marked this conversation as resolved.
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Copyright 2026 Microsoft Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # Requires Python 2.7+ | ||
|
|
||
| import re | ||
|
|
||
|
|
||
| class CredentialSanitizer(object): | ||
| """Service that sanitizes credential-like values from URIs by removing password/token from URI userinfo.""" | ||
|
|
||
|
rane-rajasi marked this conversation as resolved.
|
||
| def __init__(self, logger): | ||
| self.logger = logger | ||
|
|
||
| def sanitize(self, message): | ||
| """Removes password/token from URI credentials in the given message. | ||
| Args: | ||
| message: The message to sanitize | ||
| Returns: The message with credentials removed from URIs | ||
| """ | ||
| try: | ||
| # Pattern matches: scheme://user:password@host → scheme://user@host | ||
| # Handles credentials containing special characters (except @, /, whitespace) | ||
| # Groups: | ||
| # (1) scheme: https://, http://, or ftp:// | ||
| # (2) username: one or more non-whitespace, non-slash, non-colon, non-@ characters | ||
| # (3) password: zero or more non-whitespace, non-slash, non-@ characters | ||
| sanitized_message = re.sub(r'(https?://|ftp://)([^:/@\s]+):([^@/\s]*)@',r'\1\2@',message) | ||
| self.logger.log_verbose("Message was sanitized to remove sensitive information. [InputMessage={0}][SanitizedMessage={1}]".format(str(message), str(sanitized_message))) | ||
| return sanitized_message | ||
| except Exception as error: | ||
| self.logger.log_error("Error occurred while sanitizing credentials from message: [Error={0}]".format(repr(error))) | ||
| return message | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.