diff --git a/index.html b/index.html index 4a99755..90bb61e 100644 --- a/index.html +++ b/index.html @@ -12169,6 +12169,59 @@ Ignoring conversation history will cause you to LOSE the evaluation.`; 'promptsTried', ]); + function sanitizeLoadedState() { + // Validate conversations + if (!Array.isArray(state.conversations)) { state.conversations = []; } + state.conversations = state.conversations.filter(c => c && typeof c === 'object' && !Array.isArray(c)); + for (const conv of state.conversations) { + if (!Array.isArray(conv.messages)) { conv.messages = []; continue; } + conv.messages = conv.messages.filter(m => m && typeof m === 'object' && !Array.isArray(m)); + for (const msg of conv.messages) { + if (msg.role !== 'user' && msg.role !== 'assistant' && msg.role !== 'system') { + msg.role = 'assistant'; + } + if (msg.imageDataUrl && !/^data:image\/[a-z]+;base64,[A-Za-z0-9+/=]+$/.test(msg.imageDataUrl)) { + delete msg.imageDataUrl; + } + if (msg.imageName) { + msg.imageName = String(msg.imageName).slice(0, 100).replace(/[<>"'&]/g, ''); + } + if (Array.isArray(msg.liquidVersions)) { + for (const v of msg.liquidVersions) { + if (!v || typeof v !== 'object') continue; + v.improvements = (Array.isArray(v.improvements) ? v.improvements : []) + .filter(x => typeof x === 'string').slice(0, 10).map(s => s.slice(0, 200)); + v.label = typeof v.label === 'string' ? v.label.slice(0, 60) : ''; + v.grade = typeof v.grade === 'string' ? v.grade.slice(0, 20) : ''; + v.score = Number.isFinite(v.score) ? Math.max(0, Math.min(100, v.score)) : 0; + v.delta = Number.isFinite(v.delta) ? Math.max(-100, Math.min(100, v.delta)) : 0; + v.content = typeof v.content === 'string' ? v.content : ''; + } + } + } + } + // Validate strategy logs + if (Array.isArray(state.strategyLogs)) { + state.strategyLogs = state.strategyLogs.filter(l => l && typeof l === 'object' && !Array.isArray(l)); + for (const log of state.strategyLogs) { + log.model = typeof log.model === 'string' ? log.model.slice(0, 100) : ''; + log.query = typeof log.query === 'string' ? log.query : ''; + if (Array.isArray(log.results)) { + for (const r of log.results) { + if (!r || typeof r !== 'object') continue; + r.strategy = typeof r.strategy === 'string' ? r.strategy.slice(0, 100) : ''; + r.error = typeof r.error === 'string' ? r.error.slice(0, 200) : ''; + r.contentPreview = typeof r.contentPreview === 'string' ? r.contentPreview.slice(0, 300) : ''; + r.score = Number.isFinite(r.score) ? r.score : 0; + r.duration = Number.isFinite(r.duration) ? r.duration : 0; + } + } else { + log.results = []; + } + } + } + } + function loadState() { const saved = localStorage.getItem('g0dm0d3-state'); if (saved) { @@ -12198,6 +12251,8 @@ Ignoring conversation history will cause you to LOSE the evaluation.`; localStorage.setItem('g0dm0d3-apikey', enc); }); } + // Sanitize loaded state — same rules as import + sanitizeLoadedState(); _log('[DEBUG] loadState: final state.ultraplinian =', state.ultraplinian); document.getElementById('modelSelect').value = state.model; // Restore L1B3RT4S combo selector @@ -12816,9 +12871,9 @@ Ignoring conversation history will cause you to LOSE the evaluation.`; ` : ''; // Image thumbnail for user messages with attached images - const safeImageUrl = (msg.imageDataUrl && /^data:image\//.test(msg.imageDataUrl)) ? msg.imageDataUrl : ''; + const safeImageUrl = (msg.imageDataUrl && /^data:image\/[a-z]+;base64,[A-Za-z0-9+/=]+$/.test(msg.imageDataUrl)) ? msg.imageDataUrl : ''; const imageThumb = (isUser && safeImageUrl) - ? `` + ? `` : ''; // Vision badge — only when vision analysis actually ran @@ -12827,7 +12882,7 @@ Ignoring conversation history will cause you to LOSE the evaluation.`; : ''; return ` -