-
Couldn't load subscription status.
- Fork 111
Redact bearer tokens in error messages #88
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
SamErde
wants to merge
10
commits into
microsoft:main
Choose a base branch
from
SamErde:fix-Bearer-token-in-error-message
base: main
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.
+56
−15
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7facb25
Added 'Set-RedactedErrorMessage' to FunctionsToExport in EntraExporte…
SamErde c4e73b1
Redact sensitive information in error messages using Set-RedactedErro…
SamErde 2f803ea
Add Set-RedactedString to module and Export-Entra function.
SamErde 431d902
Create Set-RedactedString to redact bearer tokens from strings.
SamErde f0c501f
Fix script include
SamErde af7719f
Improvements to script output and cleanup
SamErde e42eadf
Update src/internal/Set-RedactedString.ps1
SamErde 2623d66
Merge branch 'main' into fix-Bearer-token-in-error-message
SamErde 0b2fcfe
Update src/internal/Set-RedactedString.ps1
SamErde 7c49a85
Remove Set-RedactedString from FunctionsToExport
SamErde 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
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,43 @@ | ||
| function Set-RedactedString { | ||
| <# | ||
| .SYNOPSIS | ||
| Redact sensitive information from strings such as error messages. | ||
| .DESCRIPTION | ||
| Set-RedactedString takes a string and redacts any sensitive information like Bearer tokens, connection strings, | ||
| passwords, and other secrets that might be contained in the message. | ||
| .EXAMPLE | ||
| Set-RedactedString -InputString $_ | ||
| Returns the string with sensitive information replaced with "[REDACTED]". | ||
| .EXAMPLE | ||
| $SensitiveString | Set-RedactedString | ||
| Accepts pipeline input for the input string. | ||
| .INPUTS | ||
| System.String | ||
| .OUTPUTS | ||
| System.String | ||
| .NOTES | ||
| This function helps prevent sensitive information from appearing in logs or being displayed to users. | ||
| #> | ||
| [CmdletBinding()] | ||
| [OutputType([string])] | ||
| param ( | ||
| # The string that may contain sensitive information to redact. | ||
| [Parameter(Mandatory, Position = 0, ValueFromPipeline)] | ||
| [string]$InputString | ||
| ) | ||
|
|
||
| process { | ||
| # Pattern matches 'Bearer ' followed by a token (non-whitespace characters) | ||
| $Pattern = '(?i)(Bearer\s+)[^\s]+' | ||
|
|
||
| # Replace the token with [REDACTED], keeping the 'Bearer ' prefix | ||
| $RedactedString = [regex]::Replace($InputString, $pattern, '${1}[REDACTED]') | ||
| } | ||
|
|
||
| end { | ||
| $RedactedString | ||
SamErde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Remove-Variable -Name InputString, BearerTokenPattern, Pattern -ErrorAction SilentlyContinue | ||
SamErde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
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.