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

@@ -195,6 +195,8 @@ public sealed class ProviderSelfHosted(Host host, string hostname) : BaseProvide
private async Task<ModelLoadResult> LoadModels(SecretStoreType storeType, string? apiKeyProvisional, CancellationToken token)
{
var secretKey = await this.GetModelLoadingSecretKey(storeType, apiKeyProvisional, isTryingSecret: true);
if (secretKey.IsUnusable)
return UnusableAPIKeyModelLoadResult();
try
{
@@ -204,8 +206,8 @@ public sealed class ProviderSelfHosted(Host host, string hostname) : BaseProvide
// rejects an empty bearer with 401, where it would have let a request without any
// authorization header through. The dialogs hand us their key field as it stands, so
// an empty string arrives here whenever the user stored no key:
if(!string.IsNullOrWhiteSpace(secretKey))
lmStudioRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", secretKey);
if(!string.IsNullOrWhiteSpace(secretKey.Key))
lmStudioRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", secretKey.Key);
using var lmStudioResponse = await this.HttpClient.SendAsync(lmStudioRequest, token);
if(!lmStudioResponse.IsSuccessStatusCode)
@@ -288,12 +290,14 @@ public sealed class ProviderSelfHosted(Host host, string hostname) : BaseProvide
private async Task<ModelLoadResult> LoadLlamaCppTextModels(string? apiKeyProvisional, CancellationToken token)
{
var secretKey = await this.GetModelLoadingSecretKey(SecretStoreType.LLM_PROVIDER, apiKeyProvisional, true);
if (secretKey.IsUnusable)
return UnusableAPIKeyModelLoadResult();
try
{
using var request = new HttpRequestMessage(HttpMethod.Get, "models");
if (!string.IsNullOrWhiteSpace(secretKey))
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", secretKey);
if (!string.IsNullOrWhiteSpace(secretKey.Key))
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", secretKey.Key);
using var response = await this.HttpClient.SendAsync(request, token);
var responseBody = await response.Content.ReadAsStringAsync(token);