Added a check for characters which an API key cannot contain (#1227)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-24 17:20:13 +01:00
1 parent c72a1948b3
commit e5a7f5423f
40 files changed
+1179 -71

No files matched your search

@@ -1,3 +1,5 @@
using AIStudio.Tools.Validation;
namespace AIStudio.Tools.PluginSystem;
/// <summary>
@@ -9,13 +11,26 @@ public static class PendingEnterpriseApiKeys
private static readonly Lock LOCK = new();
/// <summary>
/// Adds a pending API key to the list.
/// Adds a pending API key to the list, unless it cannot be sent.
/// </summary>
/// <remarks>
/// The whitespace around the key goes, e.g., a line break which came along when somebody copied
/// the key before encrypting it. A key with any other character which an HTTP header cannot carry
/// stays out: stored, it would fail with every request, and nobody on the device could change it.
/// The caller logs that, since it knows which provider of which plugin the key belongs to.
/// </remarks>
/// <param name="key">The pending API key to add.</param>
public static void Add(PendingEnterpriseApiKey key)
/// <returns>NONE when the key was added, otherwise why it was left out.</returns>
public static APIKeyIssue Add(PendingEnterpriseApiKey key)
{
var issue = APIKeyValidation.Check(key.ApiKey);
if (issue.IsProblem)
return issue;
lock (LOCK)
PENDING_KEYS.Add(key);
PENDING_KEYS.Add(key with { ApiKey = APIKeyValidation.Normalize(key.ApiKey) });
return APIKeyIssue.NONE;
}
/// <summary>