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
Apply HistorySaveStyle immediately #3785
Comments
Are you trying to ensure no sensitive data is being saved in history? We already do a number of built in precautions for saving sensitive data to history file, read more about it here, https://learn.microsoft.com/en-us/powershell/module/psreadline/about/about_psreadline?view=powershell-7.3#command-history. If there are other sensitive data you dont want to save and does not come in the included filter, you can add your own history filters with this example https://learn.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-7.3#example-7-use-historyhandler-to-filter-commands-added-to-history |
Thanks, @StevenBucher98. Just to clarify, this feature request is to make -HistorySaveStyle less tricky for common users. |
Maybe I am a little confused by your request, what exactly is tricky about it? When I do |
Did you try the example above? It appears the history is off during the sensitive command but in reality it's not. That's what's tricky about it. |
Oh I understand, it saves the commands in the same session once I turn back on the saved settings. The saving style indicates only when the saving is going to happen and not when the user necessary turns it on or off. We can clarify its usage in the docs. If this feature gets enough community interest we can reconsider changing the behavior, for now it is working by design. |
Well, I have 257 up-votes on StackOverflow from people with sensitive commands in history. That's only the people who took time to up-vote my answer among others. To me that makes it clear lots of people need a simple way to turn history off/on within a session. Would you agree? |
PSReadLine has some built-in ways to scrape sensitive commands from history. For example, you can save your plaintext password in a variable whose name contains any of these key words, then the declaration of that variable will not be kept in history file, but the commands where the variable is used won't be affected. Also, you can define the behavior of how command line gets saved to a history file by $global:__defaultHistoryHandler = (Get-PSReadLineOption).AddToHistoryHandler
Set-PSReadLineOption -AddToHistoryHandler {
param([string]$line)
$defaultResult = $global:__defaultHistoryHandler.Invoke($line)
if ($defaultResult -eq "MemoryAndFile")
{
return $line.Length -gt 3 -and $line[0] -ne ' ' -and $line[-1] -ne ';' ? "MemoryAndFile" : "MemoryOnly"
}
return $defaultResult
} |
I have also created a PR in our docs to clarify some of the behavior with |
Prerequisites
Description of the new feature/enhancement
Suggest applying HistorySaveStyle immediately. For example, I think users expect the sensitive command below not to show up in future session history, but it does:
The sensitive command shows up in future session history.
Proposed technical implementation details (optional)
No response
The text was updated successfully, but these errors were encountered: