@@ -128,7 +128,8 @@ public class HistoryItem
128
128
"Set-SecretVaultDefault" ,
129
129
"Test-SecretVault" ,
130
130
"Unlock-SecretVault" ,
131
- "Unregister-SecretVault"
131
+ "Unregister-SecretVault" ,
132
+ "Get-AzAccessToken" ,
132
133
} ;
133
134
134
135
private void ClearSavedCurrentLine ( )
@@ -511,15 +512,32 @@ private static bool IsOnLeftSideOfAnAssignment(Ast ast, out Ast rhs)
511
512
return result ;
512
513
}
513
514
515
+ private static bool IsRightSideOfAnAssignmentSafe ( Ast rhs )
516
+ {
517
+ if ( rhs is PipelineAst )
518
+ {
519
+ // Right hand side is a pipeline.
520
+ return true ;
521
+ }
522
+
523
+ if ( rhs is CommandExpressionAst cmdExprAst && cmdExprAst . Expression is MemberExpressionAst or InvokeMemberExpressionAst )
524
+ {
525
+ // Right hand side is a member access, or method invocation.
526
+ return true ;
527
+ }
528
+
529
+ return false ;
530
+ }
531
+
514
532
private static bool IsSecretMgmtCommand ( StringConstantExpressionAst strConst , out CommandAst command )
515
533
{
534
+ command = null ;
516
535
bool result = false ;
517
- command = strConst . Parent as CommandAst ;
518
536
519
- if ( command is not null )
537
+ if ( strConst . Parent is CommandAst cmdAst && ReferenceEquals ( cmdAst . CommandElements [ 0 ] , strConst ) && s_SecretMgmtCommands . Contains ( strConst . Value ) )
520
538
{
521
- result = ReferenceEquals ( command . CommandElements [ 0 ] , strConst )
522
- && s_SecretMgmtCommands . Contains ( strConst . Value ) ;
539
+ result = true ;
540
+ command = cmdAst ;
523
541
}
524
542
525
543
return result ;
@@ -568,6 +586,45 @@ private static ExpressionAst GetArgumentForParameter(CommandParameterAst param)
568
586
return null ;
569
587
}
570
588
589
+ private static bool IsCloudTokenOrSecretAccess ( StringConstantExpressionAst arg2Ast , out CommandAst command )
590
+ {
591
+ bool result = false ;
592
+ command = arg2Ast . Parent as CommandAst ;
593
+
594
+ if ( command is not null && command . CommandElements . Count >= 3
595
+ && command . CommandElements [ 0 ] is StringConstantExpressionAst nameAst
596
+ && command . CommandElements [ 1 ] is StringConstantExpressionAst arg1Ast
597
+ && command . CommandElements [ 2 ] == arg2Ast )
598
+ {
599
+ string name = nameAst . Value ;
600
+ string arg1 = arg1Ast . Value ;
601
+ string arg2 = arg2Ast . Value ;
602
+
603
+ if ( string . Equals ( name , "gcloud" , StringComparison . OrdinalIgnoreCase ) )
604
+ {
605
+ result = string . Equals ( arg1 , "auth" , StringComparison . OrdinalIgnoreCase ) &&
606
+ string . Equals ( arg2 , "print-access-token" , StringComparison . OrdinalIgnoreCase ) ;
607
+ }
608
+ else if ( string . Equals ( name , "az" , StringComparison . OrdinalIgnoreCase ) )
609
+ {
610
+ result = string . Equals ( arg1 , "account" , StringComparison . OrdinalIgnoreCase ) &&
611
+ string . Equals ( arg2 , "get-access-token" , StringComparison . OrdinalIgnoreCase ) ;
612
+ }
613
+ else if ( string . Equals ( name , "kubectl" , StringComparison . OrdinalIgnoreCase ) )
614
+ {
615
+ result = ( string . Equals ( arg1 , "get" , StringComparison . OrdinalIgnoreCase ) || string . Equals ( arg1 , "describe" , StringComparison . OrdinalIgnoreCase ) )
616
+ && ( string . Equals ( arg2 , "secrets" , StringComparison . OrdinalIgnoreCase ) || string . Equals ( arg2 , "secret" , StringComparison . OrdinalIgnoreCase ) ) ;
617
+ }
618
+ }
619
+
620
+ if ( ! result )
621
+ {
622
+ command = null ;
623
+ }
624
+
625
+ return result ;
626
+ }
627
+
571
628
public static AddToHistoryOption GetDefaultAddToHistoryOption ( string line )
572
629
{
573
630
if ( string . IsNullOrEmpty ( line ) )
@@ -618,8 +675,7 @@ public static AddToHistoryOption GetDefaultAddToHistoryOption(string line)
618
675
// If it appears on the left-hand-side of an assignment, and the right-hand-side is
619
676
// not a command invocation, we consider it sensitive.
620
677
// e.g. `$token = Get-Secret` vs. `$token = 'token-text'` or `$token, $url = ...`
621
- isSensitive = IsOnLeftSideOfAnAssignment ( innerAst , out Ast rhs )
622
- && rhs is not PipelineAst ;
678
+ isSensitive = IsOnLeftSideOfAnAssignment ( innerAst , out Ast rhs ) && ! IsRightSideOfAnAssignmentSafe ( rhs ) ;
623
679
624
680
if ( ! isSensitive )
625
681
{
@@ -629,7 +685,8 @@ public static AddToHistoryOption GetDefaultAddToHistoryOption(string line)
629
685
630
686
case StringConstantExpressionAst strConst :
631
687
isSensitive = true ;
632
- if ( IsSecretMgmtCommand ( strConst , out CommandAst command ) )
688
+ if ( IsSecretMgmtCommand ( strConst , out CommandAst command )
689
+ || IsCloudTokenOrSecretAccess ( strConst , out command ) )
633
690
{
634
691
// If it's one of the secret management commands that we can ignore, we consider it safe.
635
692
isSensitive = false ;
0 commit comments