Compare commits

...

1 Commits

Author SHA1 Message Date
diegosouzapw
0eb6aa9f9e fix(security): constant format string in the model-sync failure log (CodeQL #1407) 2026-11-23 16:44:29 -03:00
3 changed files with 33 additions and 1 deletions

View File

@@ -0,0 +1 @@
- fix(security): model-sync failure logs use a constant format string, so a provider id is never read as a format directive (CodeQL #1407)

View File

@@ -274,8 +274,12 @@ export async function syncConnectionModels(
);
return true;
} catch (err) {
// Constant format: the provider id stays a plain argument, so a "%s" in it is not a
// format directive (CodeQL #1407).
console.warn(
`[ModelSync] ${provider} (${connectionId.slice(0, 8)}): fetch failed —`,
"[ModelSync] %s (%s): fetch failed — %s",
provider,
connectionId.slice(0, 8),
(err as Error).message
);
return false;

View File

@@ -602,3 +602,30 @@ test("syncConnectionModels logs removed synced and custom models separately", as
assert.equal(logged[0], "[ModelSync] demo (conn-1): ✓ 40 models (removed: 110 synced, 3 custom)");
assert.equal(logged[1], "[ModelSync] demo (conn-2): ✓ 40 models");
});
test("CodeQL #1407: a failed sync logs with a constant format, so a provider id cannot act as one", async () => {
const { syncConnectionModels, getModelSyncInternalBaseUrl } = await loadScheduler("log-format");
const originalFetch = globalThis.fetch;
const originalWarn = console.warn;
const warned: unknown[][] = [];
globalThis.fetch = async () => {
throw new Error("socket hang up");
};
console.warn = (...args: unknown[]) => {
warned.push(args);
};
try {
assert.equal(
await syncConnectionModels("conn-fmt-1", "evil%s%o%c", getModelSyncInternalBaseUrl()),
false
);
} finally {
globalThis.fetch = originalFetch;
console.warn = originalWarn;
}
const entry = warned.find((args) => args.includes("evil%s%o%c"));
assert.ok(entry, "the provider id is logged as a plain argument");
assert.equal(typeof entry[0], "string");
assert.ok(!String(entry[0]).includes("evil"), "the format string carries no caller data");
assert.ok(entry.includes("socket hang up"), "the error message is still logged");
});