Skip to content
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

Closed
1 task done
JVimes opened this issue Aug 20, 2023 · 8 comments
Closed
1 task done

Apply HistorySaveStyle immediately #3785

JVimes opened this issue Aug 20, 2023 · 8 comments
Assignees
Labels
Resolution-By Design The behavior is by design.

Comments

@JVimes
Copy link

JVimes commented Aug 20, 2023

Prerequisites

  • Write a descriptive title.

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:

Set-PSReadLineOption -HistorySaveStyle SaveNothing

# ...User runs sensitive command...

Set-PSReadLineOption -HistorySaveStyle SaveIncrementally

The sensitive command shows up in future session history.

Proposed technical implementation details (optional)

No response

@JVimes JVimes added the Issue-Enhancement It's a feature request. label Aug 20, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. labels Aug 20, 2023
@StevenBucher98
Copy link
Collaborator

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

@StevenBucher98 StevenBucher98 removed the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Aug 21, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Aug 21, 2023
@JVimes
Copy link
Author

JVimes commented Aug 21, 2023

Thanks, @StevenBucher98. Just to clarify, this feature request is to make -HistorySaveStyle less tricky for common users.

@StevenBucher98
Copy link
Collaborator

StevenBucher98 commented Aug 21, 2023

Maybe I am a little confused by your request, what exactly is tricky about it?

When I do Set-PSReadLineOption -HistorySaveStyle SaveNothing nothing beyond this point is saved in PSReadLine history.

@StevenBucher98 StevenBucher98 added Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. and removed Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. labels Aug 21, 2023
@JVimes
Copy link
Author

JVimes commented Aug 21, 2023

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.

@StevenBucher98
Copy link
Collaborator

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.

@StevenBucher98 StevenBucher98 removed the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Aug 21, 2023
@StevenBucher98 StevenBucher98 self-assigned this Aug 21, 2023
@JVimes
Copy link
Author

JVimes commented Aug 21, 2023

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?

@daxian-dbw
Copy link
Member

daxian-dbw commented Oct 2, 2023

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 Set-PSReadLineOption -AddToHistoryHandler. Below is an example from my profile that prevents saving command lines that are less than or equal to 3 characters or those that start with a space or end with a ;. So, for command lines you don't want to be saved, just type a space and then start typing the command, or after typing the command line, add a ; at the end.

$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
}

@StevenBucher98
Copy link
Collaborator

I have also created a PR in our docs to clarify some of the behavior with HistorySaveStyle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-By Design The behavior is by design.
Projects
None yet
Development

No branches or pull requests

3 participants