Skip to content

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

@KalleOlaviNiemitalo

Description

@KalleOlaviNiemitalo

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions