fix(coding-agent/web): validate SearXNG Basic auth credentials

This commit is contained in:
某亚瑟
2026-05-06 18:08:37 +02:00
committed by can1357
parent 0b6d5dca58
commit 2626b09310
2 changed files with 67 additions and 0 deletions
@@ -119,6 +119,11 @@ function buildBasicAuthValue(username: string, password: string): string {
return Buffer.from(`${username}:${password}`, "utf-8").toString("base64");
}
/** RFC 7617 forbids C0 and C1 control characters in Basic auth credentials. */
function hasControlCharacters(value: string): boolean {
return /[\u0000-\u001F\u007F-\u009F]/u.test(value);
}
/** Find SearXNG authentication from settings or environment. Basic auth takes precedence over bearer tokens. */
function findAuth(): SearXNGAuth | null {
const basicUsername = findBasicUsername();
@@ -132,6 +137,9 @@ function findAuth(): SearXNGAuth | null {
if (basicUsername.includes(":")) {
throw new Error("SearXNG Basic auth username cannot contain ':' because RFC 7617 uses it as the separator.");
}
if (hasControlCharacters(basicUsername) || hasControlCharacters(basicPassword)) {
throw new Error("SearXNG Basic auth credentials must not contain RFC 7617 control characters.");
}
return { type: "basic", value: buildBasicAuthValue(basicUsername, basicPassword) };
}