Skip to content

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

Merged
SommerEngineering merged 13 commits into
MindWorkAI:mainfrom
SommerEngineering:api-key-character-check
Nov 24, 2026
Merged

SommerEngineering merged 13 commits into
MindWorkAI:mainfrom
SommerEngineering:api-key-character-check

Conversation

@SommerEngineering

Copy link
Copy Markdown
Member

Summary

Users paste API keys from web pages, documents, or password managers, and sometimes characters come along which an HTTP header cannot carry: a non-breaking space, a zero-width space, a line break, or a typographic quotation mark. .NET refuses such a key only while sending, with messages such as "Request headers must contain only ASCII characters.", which users cannot act on; for transcriptions, they only learned that AI Studio could not transcribe. No input checked more than whether a key was empty.

What changes:

  • One central check: APIKeyValidation in Tools/Validation/ removes spaces and line breaks around a key and reports whitespace inside it, invisible characters, and every other character beyond printable ASCII, naming that character. It checks per grapheme cluster, so a decomposed ä counts as one character. It changes a key in no other way and never writes it into a log or a message.
  • Entering a key: The provider dialogs for LLMs, embeddings, and transcriptions, the API key prompt on the start page, and the tool settings of the web search (Tavily, Staan) show the issue below the field and refuse to save. The optional key of a self-hosted provider is checked as well. RustService.SetAPIKey stores every key trimmed.
  • The web search stays on: Its keys are checked in the dialog only, not in TryValidateConfiguration. Otherwise, a bad Tavily key would switch off the whole web search, SearXNG included.
  • Configuration plugins: A key with spaces or line breaks around it is trimmed. A key with a character which an API key cannot contain is left out with a warning in the log, which names the kind of character but not the key; the provider stays. A dry run writes the warning as well.
  • Stored keys: A key stored before this check never reaches a header. BaseProvider.DecryptAPIKey replaces the twelve places where providers decrypted a key themselves, and the model loading checks its key, too. Such a request fails before it is sent, with the new failure reason INVALID_API_KEY_CHARACTERS and a message which asks to enter the key again or to contact the IT department. A key which is empty after trimming fails as a missing key instead of sending Bearer . Tavily and Staan fail the same way, and the web search then asks its other services.
  • Fireworks: The transcription with Fireworks puts its bare key into the Authorization header without parsing it. A guard test keeps every provider from parsing a key as an Authorization header.
  • Justified text: Hints and issues below fields are now justified with hyphenation everywhere, through app.css instead of an opt-in class. The same goes for the list of issues and the API key prompt.
  • Changelog entries and the German translation.

ERI tokens and passwords follow in a separate pull request, with the same check.

Related proposal or issue

None. Found while reviewing #1224.

How did you test it?

  • Ran dotnet run -- verify: 7,312 .NET tests, the trim smoke test, 379 Rust tests, Clippy, and the model sources.
  • New unit tests check:
    • the check itself, with characters of several scripts, invisible characters, and decomposed umlauts;
    • the provider dialogs, self-hosted providers included;
    • the web search fields, and that a bad key leaves the web search on;
    • the keys of configuration plugins;
    • that the model loading of OpenAI, Anthropic, Helmholtz, Ollama, and llama.cpp sends no request for an unusable key;
    • that a web search key fails before any request;
    • guards over the source code: no provider decrypts a key on its own, and none parses a key as an Authorization header.
  • Tried the provider dialog in the app: a key with an umlaut shows the issue below the field and in the list of issues.

Wiki

Users, page "Troubleshooting" (German: "Fehlerbehebung"), table "A provider doesn't answer": a new row for the messages about a space or a line break, an invisible character, or a character which an API key cannot contain. Copy the key once more from the page of the provider, or type it, and enter it again. AI Studio removes spaces and line breaks around a key by itself. If the organization provides the key, contact the IT department. Requires AI Studio v26.11.2 or newer.

IT departments, page "Enterprise Troubleshooting", section "API keys are missing": AI Studio leaves out a decrypted key with a character which an API key cannot contain, such as an invisible character or a typographic quotation mark, and writes a warning to the log, which names the kind of character but not the key. Spaces and line breaks around a key are no problem. Requires AI Studio v26.11.2 or newer.

Both are prepared for the release.

Required statements

  • Review: I have reviewed every change in this pull request and can explain it when asked.
  • License: I license my contribution in this pull request, including all commits I add to it later, under the MIT License, and I agree that it is distributed as part of MindWork AI Studio under the project license or under the MIT License.
  • Right to contribute: The contribution is my own work, or I have permission to submit it, including the consent of my employer or client where needed. To the best of my knowledge, it does not infringe the rights of others, and AI-generated parts do not reproduce third-party code under incompatible terms.
  • Changes by maintainers: I understand that the maintainers will change this pull request to fit the product, and that they may close it.

Credits (optional)

  • Credit me with my GitHub username only.
  • Do not credit me.

@SommerEngineering SommerEngineering self-assigned this Nov 24, 2026
@SommerEngineering
SommerEngineering marked this pull request as ready for review November 24, 2026 16:20
@SommerEngineering
SommerEngineering requested a review from a team as a code owner November 24, 2026 16:20
@SommerEngineering
SommerEngineering merged commit e5a7f54 into MindWorkAI:main Nov 24, 2026
11 checks passed
@SommerEngineering
SommerEngineering deleted the api-key-character-check branch November 24, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant