Allow saving command to history file if it reads a property with a sensitive name · Issue #3318 · PowerShell/PSReadLine · GitHub
Skip to content

Allow saving command to history file if it reads a property with a sensitive name #3318

Closed

Description

Prerequisites

  • Write a descriptive title.

Description of the new feature/enhancement

If I run this command, then PSReadLine does not save it to the history file by default, because of the sensitive name Password:

(Import-Clixml "${Env:HOME}\credential.clixml").GetNetworkCredential().Password | Set-Clipboard

However, the command itself does not contain any passwords. I would like PSReadLine to save this command to the history file so that I can more easily run similar commands in future PowerShell sessions.

Proposed technical implementation details (optional)

The existing implementation of [Microsoft.PowerShell.PSConsoleReadLine]::GetDefaultAddToHistoryOption considers Password a sensitive name and returns MemoryOnly, which prevents PSReadLine from saving the command to the history file. innerAst is a StringConstantExpressionAst with StringConstantType : BareWord. Its parent is a MemberExpressionAst, the grandparent is a CommandExpressionAst, and the great grandparent is a PipelineAst.

I imagine the heuristic could be changed to allow a MemberExpressionAst in which the name of the member is sensitive, if it is not at the left side of an assignment operator like $shield.Password = "12345". The VariableExpressionAst case already checks IsOnLeftSideOfAnAssignment.

Activity

  1. ghost added
    Needs-Triage 🔍It's a new issue that core contributor team needs to triage.
    on May 18, 2022
  2. KalleOlaviNiemitalo commented on May 18, 2022

    @KalleOlaviNiemitalo
    Author

    On the other hand, "12345" in $obj.SetPassword("12345") should be treated as a password. Does this likewise have a MemberExpressionAst in its parse tree?

  3. H0R5E commented on Feb 16, 2023

    @H0R5E

    I have a similar issue calling a command that passes (the name of) environment variables that contain secrets, like so:

    act -j build-demo -s AWS_ACCESS_KEY_ID -s AWS_SECRET_ACCESS_KEY -s PULUMI_ACCESS_TOKEN
    

    I don't see this as being a sensitive command as the secrets are not exposed.

  4. KalleOlaviNiemitalo commented on Mar 19, 2023

    @KalleOlaviNiemitalo
    Author

    @4cq2, it's already configurable. See #3243 (comment), Set-PSReadLineOption -AddToHistoryHandler. This issue is about changing the default behaviour to detect more cases in which the command line includes something sensitive-looking but can be analysed as safe.

  5. ghost added
    In-PRA PR is opened targeting the issue
    on Mar 21, 2023
  6. ghost removed
    In-PRA PR is opened targeting the issue
    on Mar 22, 2023
  7. ghost removed
    Needs-Triage 🔍It's a new issue that core contributor team needs to triage.
    on Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions