Files
Roman ChojnackiandClaude Opus 5.5 63b4fe6dc1 Web page: a Content-Security-Policy
The page allowed any script. It now sets a policy: scripts only from its own origin, plus WebAssembly; images from its own origin, data: and blob:, which the app creates; nothing from elsewhere. The inline script moved to shell.js, copied beside the page like keylog.js, and the canvas's inline context-menu handler went with it. Checked in headless Edge: showcase, notepad and simple start and draw the same pixels with the policy as without, the showcase's accessibility tree is the same, and the console shows no violation, with ?keylog too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:27:29 +02:00

38 lines
1.2 KiB
JavaScript

var statusEl = document.getElementById('status');
var barEl = statusEl.querySelector('.bar');
var textEl = statusEl.querySelector('.text');
var Module = {
canvas: document.getElementById('canvas'),
print: function (text) { console.log(text); },
printErr: function (text) { console.error(text); },
setStatus: function (text) {
if (!statusEl) return;
if (text) {
var m = /\((\d+)\/(\d+)\)/.exec(text);
if (m && +m[2] > 0) {
barEl.classList.add('known');
barEl.firstChild.style.width = Math.min(100, 100 * m[1] / m[2]) + '%';
}
textEl.textContent = text.replace('...', '…');
return;
}
var el = statusEl;
statusEl = null;
el.classList.add('done');
setTimeout(function () { el.remove(); }, 260);
}
};
Module.canvas.addEventListener('contextmenu', function (e) { e.preventDefault(); });
Module.canvas.addEventListener('keydown', function (e) {
if (e.key === 'Tab') e.preventDefault();
});
if (new URLSearchParams(location.search).has('keylog')) {
var keylog = document.createElement('script');
keylog.src = 'keylog.js';
document.head.appendChild(keylog);
}
Module.onRuntimeInitialized = function () { Module.setStatus(''); };