Merge pull request #10380 from uinstinct/validate-unicode

fix: validate unicode in model apikey or headers
This commit is contained in:
Dallin Romney 2026-02-11 02:59:12 -08:00 • committed by GitHub
commit d6069ed93b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,6 +12,10 @@ export interface ConfigResult<T> {
configLoadInterrupted: boolean;
}
function containsUnicode(str: string): boolean {
return /[^\x00-\x7F]/.test(str);
}
export function validateConfigYaml(
config: ConfigYaml,
): ConfigValidationError[] {
@ -32,6 +36,25 @@ export function validateConfigYaml(
if ("uses" in model) {
return;
}
// request headers to the llm api should not contain unicode characters
if (model.apiKey && containsUnicode(model.apiKey)) {
errors.push({
fatal: true,
message: `Model "${model.name}" has an API key containing unicode characters. API keys should only contain ASCII characters.`,
});
}
if (model.requestOptions?.headers) {
for (const [key, value] of Object.entries(model.requestOptions.headers)) {
if (containsUnicode(key) || containsUnicode(value)) {
errors.push({
fatal: true,
message: `Model "${model.name}" has a request header "${key}" containing unicode characters. Request headers should only contain ASCII characters.`,
});
}
}
}
// Max tokens not too close to context length
if (
model.defaultCompletionOptions?.contextLength &&