mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
fix(auth): strip line breaks from pasted keys
This commit is contained in:
20
src/utils/normalize-secret-input.ts
Normal file
20
src/utils/normalize-secret-input.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Secret normalization for copy/pasted credentials.
|
||||
*
|
||||
* Common footgun: line breaks (especially `\r`) embedded in API keys/tokens.
|
||||
* We strip line breaks anywhere, then trim whitespace at the ends.
|
||||
*
|
||||
* Intentionally does NOT remove ordinary spaces inside the string to avoid
|
||||
* silently altering "Bearer <token>" style values.
|
||||
*/
|
||||
export function normalizeSecretInput(value: unknown): string {
|
||||
if (typeof value !== "string") {
|
||||
return "";
|
||||
}
|
||||
return value.replace(/[\r\n\u2028\u2029]+/g, "").trim();
|
||||
}
|
||||
|
||||
export function normalizeOptionalSecretInput(value: unknown): string | undefined {
|
||||
const normalized = normalizeSecretInput(value);
|
||||
return normalized ? normalized : undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user