Compare commits

...

1 Commits

Author SHA1 Message Date
Markus Hartung
528fba953d fix(security): redact NVIDIA_API_KEY at the log sink in the ad-hoc diag script
CodeQL alert #866 (js/clear-text-logging) flagged the console.log wrapper
in nvidia-startswith-diag.ts, attributing the source to an unrelated
NOAUTH_IDS constant in tests/unit/executor-web-cookie-sweep.test.ts — no
real import/dataflow connects the two files.

The genuine risk in this script is independent of that attribution: an
upstream error or a validateProviderApiKey() result could echo the raw
NVIDIA_API_KEY back through err.stack/err.message/result, which the
script logs verbatim. The line() sink now strips any literal occurrence
of the key before it reaches the terminal, closing the clear-text-logging
class regardless of the exact taint path CodeQL reported.
2026-08-26 10:13:45 -03:00

View File

@@ -19,12 +19,20 @@
*/
const KEY = process.env.NVIDIA_API_KEY ?? "";
const BASE_URL = process.env.NVIDIA_BASE_URL || "https://integrate.api.nvidia.com/v1/chat/completions";
const BASE_URL =
process.env.NVIDIA_BASE_URL || "https://integrate.api.nvidia.com/v1/chat/completions";
const MODEL = process.env.NVIDIA_MODEL || "openai/gpt-oss-120b";
// Neutralize CR/LF before logging so env-derived values (NVIDIA_MODEL, etc.)
// cannot forge extra log lines (S5145 log injection).
const line = (s = "") => console.log(String(s).replace(/[\r\n]+/g, " "));
// cannot forge extra log lines (S5145 log injection). Also strip any raw
// occurrence of the API key so an upstream error/response that echoes it
// back (e.g. inside err.stack or a validation result) never reaches the
// terminal in clear text (js/clear-text-logging, CWE-312/532).
const line = (s = "") => {
let out = String(s).replace(/[\r\n]+/g, " ");
if (KEY) out = out.split(KEY).join("[REDACTED]");
console.log(out);
};
const hr = () => line("─".repeat(72));
function show(label: string, value: unknown) {
@@ -52,8 +60,13 @@ async function partA() {
});
line(" ✅ validateProviderApiKey retornou (sem crash):");
show("resultado", result);
if (typeof (result as any)?.error === "string" && (result as any).error.includes("startsWith")) {
line(" ⚠️ A mensagem de erro contém 'startsWith' → crash CAPTURADO dentro do try/catch da validação.");
if (
typeof (result as any)?.error === "string" &&
(result as any).error.includes("startsWith")
) {
line(
" ⚠️ A mensagem de erro contém 'startsWith' → crash CAPTURADO dentro do try/catch da validação."
);
}
} catch (err: any) {
line(" ❌ validateProviderApiKey LANÇOU (crash não tratado):");