Integrated console hangs if PSReadline sets AddToHistoryHandler
jhoneill opened this issue · 7 comments
I'm running preview but I think this may be in the release as well.
psreadline can save your passwords to its plaintext log. To prevent this leeholmes put out a little fragment
Set-PSReadLineOption -AddToHistoryHandler {
param([string]$line)
$sensitive = "password|asplaintext|token|key|secret"
return ($line -notmatch $sensitive)
}
I found this was hanging my Intergrated console (but not a PowerShell terminal) in VS Code.
easy to repro
ensure you have the integrated console selected.
Run a command.
paste in
Set-PSReadLineOption -AddToHistoryHandler {param([string]$line) return $true}
Re-run the previous command
This may be a psreadline bug but it only occurs in the integrated console.
@jhoneill thanks for opening this and providing detailed information, we were able to reproduce this issue and will investigate the root cause...thanks!
FWIW: Building both PSES and vscode-powershell from source based on the master branch doesn't appear to have this issue.
It's probably non-deterministic, but the issue lies with trying to make PSReadLine work in a world where the prompt doesn't stop processing. The fix will lie in ensuring the scriptblock is run on the pipeline thread.
Thinking about this, we may need to override Set-PSReadLineOption to intercept parameters that run scriptblocks and turn them into callbacks back into PSES to run things on the pipeline thread.
However that's rather complex, so I'm not going to attempt it immediately. Also, @daxian-dbw might have a better idea here.
@jhoneill I'm not sure about what causes the deadlock, but maybe a good news is that with the latest version of PSReadLine, you don't need leeholmes workaround to filter out the sensitive commands, it's built-in now :)
Hey @jhoneill, we just released v2022.4.0-preview! Could you please try PowerShell Preview for VS Code and verify this is fixed?