mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-22 04:19:40 +00:00
fix(combo): keep every unit's status when an earlier reason carries a credential label
Each unit's reason was sanitized on its own and then the joined message was sanitized again as a whole. The sanitizer redacts a credential label fail-closed, so the second pass matched an already-redacted "Password: [REDACTED]" and cut that unit's status and every later unit from the terminal message. Sanitize the unit label on its own as well and stop re-sanitizing the joined message: every upstream-derived part is already sanitized and the rest is fixed text. Adds a RED->GREEN test.
This commit is contained in:
committed by
diegosouzapw
parent
33237e2c6c
commit
37f28cbfb7
@@ -67,11 +67,13 @@ function capUnitReason(value: string): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* Make one unit's reason safe to join with the others. The joined message is sanitized
|
||||
* again as a whole, and that pass keeps only the first line, caps at 4096 chars and treats
|
||||
* a path-like span as running to the end, so one raw multi-line, HTML or oversized upstream
|
||||
* body would otherwise swallow every later unit's reason. Connection identifiers are
|
||||
* redacted before the cap: an identifier cut in half no longer matches the redaction.
|
||||
* Make one unit's reason (or label) safe to join with the others. Each part is sanitized on
|
||||
* its own because a pass over the joined message keeps only the first line, caps at 4096
|
||||
* chars, treats a path-like span as running to the end and redacts a credential label
|
||||
* fail-closed (everything after it), so one raw multi-line, HTML, oversized or
|
||||
* credential-bearing upstream body would otherwise swallow every later unit's reason.
|
||||
* Connection identifiers are redacted before the cap: an identifier cut in half no longer
|
||||
* matches the redaction.
|
||||
*/
|
||||
function normalizeUnitReason(reason: string): string {
|
||||
const sanitized = sanitizeErrorMessage(collapseControlCharacters(reason));
|
||||
@@ -84,6 +86,7 @@ function pushOutcome(outcomes: RuntimeUnitOutcomes, unitKey: string, raw: ComboE
|
||||
// The free-tier check reads the full reason; the signal can sit past the display cap.
|
||||
const entry: ComboErrorEntry = {
|
||||
...raw,
|
||||
model: normalizeUnitReason(raw.model),
|
||||
error: normalizeUnitReason(raw.error),
|
||||
...(isFreeTierRefusalOutcome(raw) ? { freeTierRefusal: true } : {}),
|
||||
};
|
||||
@@ -174,7 +177,12 @@ export async function withRuntimeUnitOutcomes(
|
||||
if ((response.status === 400 || response.status === 413) && isContextOverflow400(previous)) {
|
||||
return response;
|
||||
}
|
||||
const message = sanitizeErrorMessage(formatComboOutcomes(outcomes.entries));
|
||||
// Every upstream-derived part (label and reason) was sanitized on its own in pushOutcome
|
||||
// and the rest is fixed text, so the joined message is not sanitized again as a whole: that
|
||||
// pass matched an already-redacted "Password: [REDACTED]" and cut the unit's status and
|
||||
// every later unit. The formatter lists at most 5 entries, each a label and a reason of
|
||||
// <= 300 chars, so the message stays under the sanitizer's 4096-char budget.
|
||||
const message = formatComboOutcomes(outcomes.entries);
|
||||
if (!message) return response;
|
||||
const headers = new Headers(response.headers);
|
||||
headers.delete("content-length");
|
||||
|
||||
@@ -356,3 +356,20 @@ test("the per-unit cap does not split a character in half", async () => {
|
||||
assert.match(message, /provider-a\/model-x: provider — x+ \(HTTP 500\)/);
|
||||
assert.match(message, SECOND_DOWN);
|
||||
});
|
||||
|
||||
// The sanitizer redacts a credential label fail-closed: everything after "Password:" goes.
|
||||
// Each reason is already sanitized on its own, so a second pass over the joined message
|
||||
// matched the redacted label again and dropped that unit's status and every later unit.
|
||||
test("a credential label in an earlier unit's reason keeps that unit's status and the later units", async () => {
|
||||
const message = await twoUnitMessage(
|
||||
"ru-terminal-credential-label",
|
||||
500,
|
||||
"upstream rejected: Password: hunter2 for account"
|
||||
);
|
||||
assert.doesNotMatch(message, /hunter2/);
|
||||
assert.match(
|
||||
message,
|
||||
/^provider-a\/model-x: provider — upstream rejected: Password: \[REDACTED\] \(HTTP 500\); /
|
||||
);
|
||||
assert.match(message, SECOND_DOWN);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user