Skip to content

Commit 2cd9794

Browse files
committed
fix(web-content): strip controls from provider secrets
1 parent 469dbbd commit 2cd9794

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎packages/web-content-core/src/provider-runtime-shared.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ describe("readWebProviderEnvValue", () => {
3030
it("normalizes env credentials before returning them", () => {
3131
expect(readWebProviderEnvValue(["API_KEY"], { API_KEY: " key\r\nvalue🙂 " })).toBe("keyvalue");
3232
});
33+
34+
it("strips embedded controls from env credentials while preserving ordinary spaces", () => {
35+
expect(readWebProviderEnvValue(["API_KEY"], { API_KEY: " sk-\u0000ab\tc\u007f\u0085 " })).toBe(
36+
"sk-abc",
37+
);
38+
expect(readWebProviderEnvValue(["API_KEY"], { API_KEY: " Bearer token value " })).toBe(
39+
"Bearer token value",
40+
);
41+
});
3342
});
3443

3544
describe("hasWebProviderEntryCredential", () => {

‎packages/web-content-core/src/provider-runtime-shared.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ function normalizeSecretInput(value: unknown): string {
5656
let latin1Only = "";
5757
for (const char of collapsed) {
5858
const codePoint = char.codePointAt(0);
59-
if (typeof codePoint === "number" && codePoint <= 0xff) {
59+
const isControl =
60+
typeof codePoint === "number" &&
61+
((codePoint >= 0x00 && codePoint <= 0x1f) ||
62+
codePoint === 0x7f ||
63+
(codePoint >= 0x80 && codePoint <= 0x9f));
64+
if (typeof codePoint === "number" && codePoint <= 0xff && !isControl) {
6065
latin1Only += char;
6166
}
6267
}

0 commit comments

Comments
 (0)