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

obfuscate pwd in sql and kql kernel display events #3472

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/Microsoft.DotNet.Interactive.SqlServer/MsSqlKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ public override async Task ConnectAsync()

protected override string CreateVariableDeclaration(string name, object value)
{
if (value is PasswordString ps)
{
value = ps.GetClearTextPassword();
}

return $"DECLARE @{name} {MapToSqlDataType(name, value)} = {MapToSqlValueDeclaration(value)};";

static string MapToSqlDataType(string name, object value)
Expand Down Expand Up @@ -92,10 +87,6 @@ protected override bool CanDeclareVariable(string name, object value, out string
msg = default;
try
{
if (value is PasswordString)
{
return true;
}
SqlMetaData.InferFromValue(
value,
name);
Expand Down
25 changes: 23 additions & 2 deletions src/Microsoft.DotNet.Interactive.SqlServer/ToolsServiceKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.CommandLine.Parsing;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -398,8 +399,23 @@ private string PrependVariableDeclarationsToCode(SubmitCode command, KernelInvoc

foreach (var variableNameAndValue in _variables)
{
var declareStatement = CreateVariableDeclaration(variableNameAndValue.Key, variableNameAndValue.Value);
context.Display($"Adding shared variable declaration statement : {declareStatement}");
var value = variableNameAndValue.Value;

if (value is PasswordString ps)
{
value = ps.GetClearTextPassword();
}

var declareStatement = CreateVariableDeclaration(variableNameAndValue.Key, value);

var displayStatement = declareStatement;

if (variableNameAndValue.Value is PasswordString pwd)
{
displayStatement = displayStatement.Replace(pwd.GetClearTextPassword(), pwd.ToString());
}

context.Display($"Adding shared variable declaration statement : {displayStatement}");
sb.AppendLine(declareStatement);
}

Expand Down Expand Up @@ -433,6 +449,11 @@ private string PrependVariableDeclarationsToCode(SubmitCode command, KernelInvoc
throw new ArgumentNullException(nameof(value), $"Sharing null values is not supported at this time.");
}

if (value is PasswordString ps)
{
value = ps.GetClearTextPassword();
}

if (!CanDeclareVariable(name, value, out string msg))
{
throw new ArgumentException($"Cannot support value of Type {value.GetType()}. {msg}");
Expand Down