Skip to content

LIBERATED AI CHAT

TypeScript

fix: close all remaining XSS sinks, harden import + load schemas

faberc13246ab13ce
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)
- ? `<img class="message-image-thumb" src="${safeImageUrl}" alt="${escapeHtml(msg.imageName || 'image')}" onclick="window.open(this.src,'_blank')">`
+ ? `<img class="message-image-thumb" src="${escapeAttr(safeImageUrl)}" alt="${escapeAttr(msg.imageName || 'image')}">`
: '';
// Vision badge — only when vision analysis actually ran
@@ -12827,7 +12882,7 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;
: '';
return `
- <div class="message ${msg.role}" data-idx="${idx}">
+ <div class="message ${msg.role === 'user' ? 'user' : 'assistant'}" data-idx="${idx}">
<div class="message-avatar">${isUser ? '_&lt;' : '&gt;_'}</div>
<div class="message-wrapper">
${magicInfo}
@@ -13135,12 +13190,17 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;
const versionItems = versions.map((v, i) => {
const isActive = i === currentVersion;
const delta = i > 0 ? `+${(v.score - versions[i-1].score).toFixed(0)}` : '';
+ const safeVLabel = escapeAttr(String(v.label || '').slice(0, 60));
+ const safeVScore = Number.isFinite(v.score) ? v.score : 0;
+ const safeVImps = Array.isArray(v.improvements)
+ ? v.improvements.filter(x => typeof x === 'string').slice(0, 3).map(s => s.slice(0, 40)).join(', ')
+ : '';
return `
<div class="liquid-version-item ${isActive ? 'active' : ''}"
- onclick="event.stopPropagation(); revertToLiquidVersion(${idx}, ${i})"
- title="${v.label}: Score ${v.score}${v.improvements?.length ? ' - ' + v.improvements.join(', ') : ''}">
+ onclick="event.stopPropagation(); revertToLiquidVersion(${Number(idx)}, ${Number(i)})"
+ title="${safeVLabel}: Score ${safeVScore}${safeVImps ? ' - ' + escapeAttr(safeVImps) : ''}">
<span class="liquid-version-num">v${i}</span>
- <span class="liquid-version-score">${v.score}</span>
+ <span class="liquid-version-score">${safeVScore}</span>
${delta ? `<span class="liquid-version-delta">${delta}</span>` : ''}
</div>
`;
@@ -16608,30 +16668,72 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;
if (imported[key] !== undefined) candidate[key] = imported[key];
}
- // Sanitize conversations: strip dangerous image URLs, validate structure
- if (Array.isArray(candidate.conversations)) {
- for (const conv of candidate.conversations) {
- if (!Array.isArray(conv.messages)) { conv.messages = []; continue; }
- for (const msg of conv.messages) {
- // Only allow data:image/ URLs for inline images
- if (msg.imageDataUrl && !/^data:image\//.test(msg.imageDataUrl)) {
- delete msg.imageDataUrl;
- }
- // Sanitize liquid version improvements
- if (Array.isArray(msg.liquidVersions)) {
- for (const v of msg.liquidVersions) {
- if (Array.isArray(v.improvements)) {
- v.improvements = v.improvements
- .filter(x => typeof x === 'string')
- .slice(0, 10)
- .map(s => s.slice(0, 200));
- }
- if (typeof v.label === 'string') v.label = v.label.slice(0, 60);
- if (typeof v.grade === 'string') v.grade = v.grade.slice(0, 20);
- if (!Number.isFinite(v.score)) v.score = 0;
- if (!Number.isFinite(v.delta)) v.delta = 0;
+ // Sanitize conversations: validate structure, strip dangerous values
+ if (!Array.isArray(candidate.conversations)) {
+ candidate.conversations = [];
+ }
+ candidate.conversations = candidate.conversations.filter(conv =>
+ conv && typeof conv === 'object' && !Array.isArray(conv)
+ );
+ for (const conv of candidate.conversations) {
+ if (!Array.isArray(conv.messages)) { conv.messages = []; continue; }
+ conv.messages = conv.messages.filter(msg =>
+ msg && typeof msg === 'object' && !Array.isArray(msg)
+ );
+ for (const msg of conv.messages) {
+ // Restrict role to known values
+ if (msg.role !== 'user' && msg.role !== 'assistant' && msg.role !== 'system') {
+ msg.role = 'assistant';
+ }
+ // Only allow strict base64 data:image/ URLs
+ if (msg.imageDataUrl && !/^data:image\/[a-z]+;base64,[A-Za-z0-9+/=]+$/.test(msg.imageDataUrl)) {
+ delete msg.imageDataUrl;
+ }
+ // Sanitize imageName
+ if (msg.imageName) {
+ msg.imageName = String(msg.imageName).slice(0, 100).replace(/[<>"'&]/g, '');
+ }
+ // Sanitize liquid version history
+ if (Array.isArray(msg.liquidVersions)) {
+ for (const v of msg.liquidVersions) {
+ if (!v || typeof v !== 'object') continue;
+ if (Array.isArray(v.improvements)) {
+ v.improvements = v.improvements
+ .filter(x => typeof x === 'string')
+ .slice(0, 10)
+ .map(s => s.slice(0, 200));
+ } else {
+ v.improvements = [];
}
+ 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 : '';
+ }
+ }
+ }
+ }
+
+ // Sanitize strategy logs
+ if (Array.isArray(candidate.strategyLogs)) {
+ candidate.strategyLogs = candidate.strategyLogs.filter(log =>
+ log && typeof log === 'object' && !Array.isArray(log)
+ );
+ for (const log of candidate.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 = [];
}
}
}
@@ -16814,17 +16916,17 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;
const logsHtml = state.strategyLogs.map(log => `
<div class="log-entry">
<div class="log-header">
- <span>${new Date(log.timestamp).toLocaleString()}</span>
- <span>${log.model}</span>
+ <span>${escapeHtml(new Date(log.timestamp).toLocaleString())}</span>
+ <span>${escapeHtml(String(log.model || ''))}</span>
</div>
- <div class="log-query">${escapeHtml(log.query)}</div>
+ <div class="log-query">${escapeHtml(log.query || '')}</div>
<div class="log-results">
- ${log.results.map((r, i) => `
+ ${(Array.isArray(log.results) ? log.results : []).map((r, i) => `
<div class="log-result ${i === 0 ? 'winner' : ''}">
- <span class="log-strategy">${i === 0 ? '🏆 ' : ''}${r.strategy}</span>
- <span class="log-score ${r.score < 0 ? 'negative' : ''}">${r.score.toFixed(0)} pts</span>
- <span class="log-duration">${r.duration}ms</span>
- <span class="log-preview">${r.error ? '❌ ' + r.error : escapeHtml(r.contentPreview || '')}</span>
+ <span class="log-strategy">${i === 0 ? '🏆 ' : ''}${escapeHtml(String(r.strategy || ''))}</span>
+ <span class="log-score ${(Number(r.score) || 0) < 0 ? 'negative' : ''}">${(Number(r.score) || 0).toFixed(0)} pts</span>
+ <span class="log-duration">${Number(r.duration) || 0}ms</span>
+ <span class="log-preview">${r.error ? '❌ ' + escapeHtml(String(r.error)) : escapeHtml(r.contentPreview || '')}</span>
</div>
`).join('')}
</div>