fix: deep Magic schema sanitization, correct No-Log claim

- Extract _sanitizeMagic() shared helper — covers all nested structures
- Validate thinkingModels values (filter null entries, coerce status/score)
- Filter thinkingLogs, all_scores, scores arrays (remove non-objects, normalize fields)
- Coerce triggers_found to string array, validate tastemakerScore shape
- Normalize winnerModel, topModel, model, systemPrompt, enhancedUserPrompt as strings
- Guard AutoTune .toFixed() with Number.isFinite(), coerce top_k and all param grid values
- Coerce liquidIterations/liquidImprovement, Parseltongue summary counters
- Correct No-Log Mode description: local metadata only, not provider-side

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
faber
2026-07-13 08:36:38 -04:00
parent e09dd6b222
commit ca70d4c9d4

View File

@@ -3666,7 +3666,7 @@
<input type="checkbox" id="noLogMode" checked>
<label for="noLogMode" style="margin: 0;">No-Log Mode</label>
</div>
<small style="color: #888; display: block; margin-top: 4px;">Enhanced privacy - requests not logged by OpenRouter.</small>
<small style="color: #888; display: block; margin-top: 4px;">Privacy preference — recorded in local telemetry metadata only. Does not change provider-side logging.</small>
</div>
</div>
<div class="settings-section">
@@ -12169,6 +12169,102 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;
'promptsTried',
]);
function _sanitizeMagic(m) {
if (m.mode != null) m.mode = String(m.mode).slice(0, 30);
if (m.score != null) m.score = Number(m.score) || 0;
if (m.duration != null) m.duration = String(m.duration).slice(0, 20);
if (m.variants_succeeded != null) m.variants_succeeded = parseInt(m.variants_succeeded) || 0;
if (m.variants_total != null) m.variants_total = parseInt(m.variants_total) || 0;
if (m.variants_refused != null) m.variants_refused = parseInt(m.variants_refused) || 0;
if (m.topScore != null) m.topScore = String(m.topScore).slice(0, 20);
if (m.combos_attempted != null) m.combos_attempted = parseInt(m.combos_attempted) || 0;
if (m.combos_succeeded != null) m.combos_succeeded = parseInt(m.combos_succeeded) || 0;
if (m.combos_failed != null) m.combos_failed = parseInt(m.combos_failed) || 0;
if (m.winnerModel != null) m.winnerModel = String(m.winnerModel).slice(0, 100);
if (m.topModel != null) m.topModel = String(m.topModel).slice(0, 100);
if (m.model != null) m.model = String(m.model).slice(0, 100);
if (m.template != null) m.template = String(m.template).slice(0, 100);
if (m.combo != null) m.combo = String(m.combo).slice(0, 100);
if (m.technique != null) m.technique = String(m.technique).slice(0, 100);
if (m.techniqueLabel != null) m.techniqueLabel = String(m.techniqueLabel).slice(0, 100);
if (m.tier != null) m.tier = String(m.tier).slice(0, 20);
if (m.systemPrompt != null) m.systemPrompt = String(m.systemPrompt).slice(0, 2000);
if (m.enhancedUserPrompt != null) m.enhancedUserPrompt = String(m.enhancedUserPrompt).slice(0, 2000);
if (m.judgeReasoning != null) m.judgeReasoning = String(m.judgeReasoning).slice(0, 500);
if (m.prefix != null) m.prefix = String(m.prefix).slice(0, 500);
if (m.winnerScore != null) m.winnerScore = String(m.winnerScore).slice(0, 20);
if (m.successfulModels != null) m.successfulModels = parseInt(m.successfulModels) || 0;
if (m.totalModels != null) m.totalModels = parseInt(m.totalModels) || 0;
if (m.scoredResponses != null) m.scoredResponses = parseInt(m.scoredResponses) || 0;
if (m.attempt != null) m.attempt = parseInt(m.attempt) || 1;
if (m.temperature != null) m.temperature = Number(m.temperature) || 0;
if (m.topP != null) m.topP = Number(m.topP) || 0;
if (m.thinkingModels && typeof m.thinkingModels === 'object' && !Array.isArray(m.thinkingModels)) {
for (const [k, v] of Object.entries(m.thinkingModels)) {
if (!v || typeof v !== 'object') { delete m.thinkingModels[k]; continue; }
v.status = typeof v.status === 'string' ? v.status.slice(0, 20) : 'unknown';
v.score = v.score !== null && v.score !== undefined ? Number(v.score) || 0 : null;
}
} else if (m.thinkingModels) {
delete m.thinkingModels;
}
if (Array.isArray(m.thinkingLogs)) {
m.thinkingLogs = m.thinkingLogs.filter(l => l && typeof l === 'object').map(l => ({
type: typeof l.type === 'string' ? l.type.slice(0, 20) : 'info',
time: Number(l.time) || 0,
message: typeof l.message === 'string' ? l.message.slice(0, 200) : ''
}));
} else if (m.thinkingLogs) {
delete m.thinkingLogs;
}
if (Array.isArray(m.all_scores)) {
m.all_scores = m.all_scores.filter(s => s && typeof s === 'object').map(s => ({
template: typeof s.template === 'string' ? s.template.slice(0, 100) : '',
score: Number(s.score) || 0
}));
} else if (m.all_scores) {
delete m.all_scores;
}
if (Array.isArray(m.scores)) {
m.scores = m.scores.filter(s => s && typeof s === 'object').map(s => ({
technique: typeof s.technique === 'string' ? s.technique.slice(0, 100) : '',
score: Number(s.score) || 0
}));
} else if (m.scores) {
delete m.scores;
}
if (m.triggers_found != null) {
m.triggers_found = Array.isArray(m.triggers_found)
? m.triggers_found.filter(t => typeof t === 'string').slice(0, 20).map(t => t.slice(0, 100))
: [];
}
if (m.tastemakerScore && typeof m.tastemakerScore === 'object') {
const ts = m.tastemakerScore;
ts.overall = ts.overall != null ? String(ts.overall).slice(0, 10) : '';
ts.grade = ts.grade != null ? String(ts.grade).slice(0, 10) : '';
ts.gradeEmoji = ts.gradeEmoji != null ? String(ts.gradeEmoji).slice(0, 4) : '';
ts.gradeColor = ts.gradeColor != null ? String(ts.gradeColor).slice(0, 20) : '';
ts.queryType = ts.queryType != null ? String(ts.queryType).slice(0, 30) : '';
} else if (m.tastemakerScore) {
delete m.tastemakerScore;
}
if (m.autoTune && typeof m.autoTune === 'object') {
const at = m.autoTune;
at.confidence = Number(at.confidence) || 0;
at.conversationLength = Number(at.conversationLength) || 0;
at.godmodeBoost = at.godmodeBoost === true;
if (at.strategy != null) at.strategy = String(at.strategy).slice(0, 20);
if (at.context != null) at.context = String(at.context).slice(0, 30);
if (at.params && typeof at.params === 'object') {
for (const k of Object.keys(at.params)) {
at.params[k] = Number(at.params[k]) || 0;
}
}
} else if (m.autoTune) {
delete m.autoTune;
}
}
function sanitizeLoadedState() {
// Validate conversations
if (!Array.isArray(state.conversations)) { state.conversations = []; }
@@ -12210,30 +12306,7 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;
if (msg.liquidIterations != null) msg.liquidIterations = parseInt(msg.liquidIterations) || 0;
if (msg.liquidImprovement != null) msg.liquidImprovement = Number(msg.liquidImprovement) || 0;
if (msg.magic && typeof msg.magic === 'object') {
const m = msg.magic;
if (m.mode != null) m.mode = String(m.mode).slice(0, 30);
if (m.score != null) m.score = Number(m.score) || 0;
if (m.duration != null) m.duration = String(m.duration).slice(0, 20);
if (m.variants_succeeded != null) m.variants_succeeded = parseInt(m.variants_succeeded) || 0;
if (m.variants_total != null) m.variants_total = parseInt(m.variants_total) || 0;
if (m.variants_refused != null) m.variants_refused = parseInt(m.variants_refused) || 0;
if (m.topScore != null) m.topScore = String(m.topScore).slice(0, 20);
if (m.combos_attempted != null) m.combos_attempted = parseInt(m.combos_attempted) || 0;
if (m.combos_succeeded != null) m.combos_succeeded = parseInt(m.combos_succeeded) || 0;
if (m.combos_failed != null) m.combos_failed = parseInt(m.combos_failed) || 0;
if (m.autoTune && typeof m.autoTune === 'object') {
const at = m.autoTune;
at.confidence = Number(at.confidence) || 0;
at.conversationLength = Number(at.conversationLength) || 0;
at.godmodeBoost = at.godmodeBoost === true;
if (at.strategy != null) at.strategy = String(at.strategy).slice(0, 20);
if (at.context != null) at.context = String(at.context).slice(0, 30);
if (at.params && typeof at.params === 'object') {
for (const k of Object.keys(at.params)) {
at.params[k] = Number(at.params[k]) || 0;
}
}
}
_sanitizeMagic(msg.magic);
}
}
}
@@ -16764,30 +16837,7 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;
if (msg.liquidIterations != null) msg.liquidIterations = parseInt(msg.liquidIterations) || 0;
if (msg.liquidImprovement != null) msg.liquidImprovement = Number(msg.liquidImprovement) || 0;
if (msg.magic && typeof msg.magic === 'object') {
const m = msg.magic;
if (m.mode != null) m.mode = String(m.mode).slice(0, 30);
if (m.score != null) m.score = Number(m.score) || 0;
if (m.duration != null) m.duration = String(m.duration).slice(0, 20);
if (m.variants_succeeded != null) m.variants_succeeded = parseInt(m.variants_succeeded) || 0;
if (m.variants_total != null) m.variants_total = parseInt(m.variants_total) || 0;
if (m.variants_refused != null) m.variants_refused = parseInt(m.variants_refused) || 0;
if (m.topScore != null) m.topScore = String(m.topScore).slice(0, 20);
if (m.combos_attempted != null) m.combos_attempted = parseInt(m.combos_attempted) || 0;
if (m.combos_succeeded != null) m.combos_succeeded = parseInt(m.combos_succeeded) || 0;
if (m.combos_failed != null) m.combos_failed = parseInt(m.combos_failed) || 0;
if (m.autoTune && typeof m.autoTune === 'object') {
const at = m.autoTune;
at.confidence = Number(at.confidence) || 0;
at.conversationLength = Number(at.conversationLength) || 0;
at.godmodeBoost = at.godmodeBoost === true;
if (at.strategy != null) at.strategy = String(at.strategy).slice(0, 20);
if (at.context != null) at.context = String(at.context).slice(0, 30);
if (at.params && typeof at.params === 'object') {
for (const k of Object.keys(at.params)) {
at.params[k] = Number(at.params[k]) || 0;
}
}
}
_sanitizeMagic(msg.magic);
}
}
}