Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/UnifiSharp/UnifiClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@ public sealed record UnifiClientOptions

return new UnifiClientOptions { BaseUrl = new Uri(baseUrl), ApiKey = apiKey, VerifyTls = verifyTls };
}

/// <summary>
/// Redacted representation. The synthesized record <c>ToString()</c> would
/// otherwise print <see cref="ApiKey"/>, leaking it into any log or
/// interpolated string. The key is never emitted.
/// </summary>
public override string ToString() =>
$"UnifiClientOptions {{ BaseUrl = {BaseUrl}, ApiKey = ***, VerifyTls = {VerifyTls} }}";
}
15 changes: 15 additions & 0 deletions tests/UnifiSharp.Tests/UnifiClientOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ public void Create_builds_a_client()

Assert.NotNull(client);
}

[Fact]
public void ToString_does_not_leak_the_api_key()
{
var options = new UnifiClientOptions
{
BaseUrl = new Uri("https://192.168.1.1/proxy/network/integration/v1"),
ApiKey = "super-secret-api-key",
};

var text = options.ToString();

Assert.DoesNotContain("super-secret-api-key", text);
Assert.Contains("***", text);
}
}
Loading