Skip to content

Commit 00c9ac5

Browse files
authored
fix(secrets): skip PLAINTEXT_FOUND for known non-secret apiKey markers (#97622)
Exclude models.providers.*.apiKey values that match isNonSecretApiKeyMarker (e.g., lmstudio-local, ollama-local) from secrets audit plaintext warnings. Regression test covers marker bypass and real-key flagging. Closes #89233
1 parent a202dd0 commit 00c9ac5

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

‎src/secrets/audit.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,4 +771,65 @@ describe("secrets audit", () => {
771771
),
772772
).toBe(true);
773773
});
774+
775+
it("does not flag openclaw.json model provider apiKey marker values as plaintext", async () => {
776+
await writeJsonFile(fixture.configPath, {
777+
models: {
778+
providers: {
779+
lmstudio: {
780+
baseUrl: "http://127.0.0.1:1234/v1",
781+
api: "openai-completions",
782+
apiKey: "lmstudio-local",
783+
models: [{ id: "lmstudio-local", name: "lmstudio-local" }],
784+
},
785+
ollama: {
786+
baseUrl: "http://127.0.0.1:11434/v1",
787+
api: "openai-completions",
788+
apiKey: "ollama-local",
789+
models: [{ id: "ollama-local", name: "ollama-local" }],
790+
},
791+
openai: {
792+
baseUrl: "https://api.openai.com/v1",
793+
api: "openai-completions",
794+
apiKey: "sk-real-plaintext",
795+
models: [{ id: "gpt-5", name: "gpt-5" }],
796+
},
797+
},
798+
},
799+
});
800+
await writeJsonFile(fixture.authStorePath, {
801+
version: 1,
802+
profiles: {},
803+
});
804+
await fs.writeFile(fixture.envPath, "", "utf8");
805+
806+
const report = await runSecretsAudit({ env: fixture.env });
807+
expect(
808+
hasFinding(
809+
report,
810+
(entry) =>
811+
entry.code === "PLAINTEXT_FOUND" &&
812+
entry.file === fixture.configPath &&
813+
entry.jsonPath === "models.providers.lmstudio.apiKey",
814+
),
815+
).toBe(false);
816+
expect(
817+
hasFinding(
818+
report,
819+
(entry) =>
820+
entry.code === "PLAINTEXT_FOUND" &&
821+
entry.file === fixture.configPath &&
822+
entry.jsonPath === "models.providers.ollama.apiKey",
823+
),
824+
).toBe(false);
825+
expect(
826+
hasFinding(
827+
report,
828+
(entry) =>
829+
entry.code === "PLAINTEXT_FOUND" &&
830+
entry.file === fixture.configPath &&
831+
entry.jsonPath === "models.providers.openai.apiKey",
832+
),
833+
).toBe(true);
834+
});
774835
});

‎src/secrets/audit.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ function collectConfigSecrets(params: {
221221
) {
222222
continue;
223223
}
224+
if (
225+
target.entry.id === "models.providers.*.apiKey" &&
226+
typeof target.value === "string" &&
227+
isNonSecretApiKeyMarker(target.value)
228+
) {
229+
continue;
230+
}
224231
if (!hasPlaintext) {
225232
continue;
226233
}

0 commit comments

Comments
 (0)