utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | 5deee259aed4ac8e52820dae53e3aa258de45160e91a9acaa87637fc3b44141d |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-12 13:47 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-12 13:47 +02:00 |
| Parents | 0715f3192d0d |
1 file changed
added tests/xss-nombres.mjs +70 −0
| @@ -0,0 +1,70 @@ | ||
| 1 | +// Un nombre de fichero HOSTIL no puede convertirse en HTML en el menú del «@». | |
| 2 | +// | |
| 3 | +// Por qué un directorio falso y no OPFS: OPFS no admite nombres con «<», «>» ni | |
| 4 | +// «=» («Name is not allowed»), pero un proyecto real se abre desde el disco con | |
| 5 | +// el selector de carpetas, y ahí sí pueden existir. El recorrido del proyecto | |
| 6 | +// solo usa `values()` con `kind` y `name`, así que un directorio falso con esos | |
| 7 | +// nombres ejercita exactamente el mismo camino que un disco real. | |
| 8 | +// | |
| 9 | +// Controles: el nombre hostil tiene que estar en el proyecto (si no, el test no | |
| 10 | +// prueba nada) y el menú tiene que abrirse con filas. | |
| 11 | +import { chromium } from 'playwright'; | |
| 12 | +const BASE = process.env.BASE || 'http://localhost:8799'; | |
| 13 | +let fails = 0; | |
| 14 | +const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; | |
| 15 | + | |
| 16 | +const b = await chromium.launch(); | |
| 17 | +const ctx = await b.newContext(); | |
| 18 | +await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); | |
| 19 | +const p = await ctx.newPage(); | |
| 20 | +p.on('pageerror', e => { console.log('❌ pageerror: ' + e.message); fails++; }); | |
| 21 | + | |
| 22 | +const ejecutado = []; | |
| 23 | +await p.exposeFunction('__xss', d => { ejecutado.push(d); }); | |
| 24 | +await p.addInitScript(() => { window.__marcaXss = () => window.__xss('onerror'); }); | |
| 25 | + | |
| 26 | +const HOSTIL = '<img src=x onerror=window.__marcaXss()>.js'; | |
| 27 | +const OTRO = '<b onmouseover=window.__marcaXss()>negrita</b>.txt'; | |
| 28 | + | |
| 29 | +await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); | |
| 30 | +await p.waitForTimeout(1200); | |
| 31 | + | |
| 32 | +// Directorio falso con nombres hostiles. Solo implementa lo que recorre el código. | |
| 33 | +const abierto = await p.evaluate(async ({ a, c }) => { | |
| 34 | + const fichero = n => ({ kind: 'file', name: n, async getFile() { return new File(['// x'], n); } }); | |
| 35 | + const raiz = { | |
| 36 | + kind: 'directory', name: 'proyecto', | |
| 37 | + async *values() { for (const n of [a, c, 'normal.js']) yield fichero(n); }, | |
| 38 | + async getDirectoryHandle() { throw new Error('no hace falta'); }, | |
| 39 | + async getFileHandle(n) { return fichero(n); }, | |
| 40 | + }; | |
| 41 | + const code = await import('/js/tools/code.js'); | |
| 42 | + return await code.openProject(raiz); | |
| 43 | +}, { a: HOSTIL, c: OTRO }); | |
| 44 | +ok('⊕ control: el proyecto con nombres hostiles se ha abierto', abierto === 'proyecto', `devuelto: ${abierto}`); | |
| 45 | + | |
| 46 | +await p.click('#prompt'); | |
| 47 | +await p.keyboard.type('@'); | |
| 48 | +await p.waitForTimeout(900); | |
| 49 | + | |
| 50 | +const m = await p.evaluate(() => { | |
| 51 | + const menu = document.getElementById('menu'); | |
| 52 | + return { | |
| 53 | + oculto: menu.hidden, | |
| 54 | + textos: [...menu.querySelectorAll('.menu-item')].map(x => x.textContent), | |
| 55 | + etiquetasInyectadas: menu.querySelectorAll('.menu-item img, .menu-item b b, .menu-item [onerror], .menu-item [onmouseover]').length, | |
| 56 | + }; | |
| 57 | +}); | |
| 58 | + | |
| 59 | +ok('⊕ control: el menú del «@» está abierto y con filas', !m.oculto && m.textos.length > 0, `${m.textos.length} filas`); | |
| 60 | +ok('el nombre hostil aparece como TEXTO, con sus caracteres intactos', | |
| 61 | + m.textos.some(x => x.includes('<img src=x onerror=')), (m.textos.find(x => x.includes('img')) || m.textos[0] || '').slice(0, 70)); | |
| 62 | +ok('no se ha inyectado NINGUNA etiqueta en la fila', m.etiquetasInyectadas === 0, `${m.etiquetasInyectadas} etiqueta(s)`); | |
| 63 | + | |
| 64 | +await p.hover('.menu-item').catch(() => {}); | |
| 65 | +await p.waitForTimeout(500); | |
| 66 | +ok('NADA se ha ejecutado', ejecutado.length === 0, ejecutado.join(', ') || 'ninguna llamada'); | |
| 67 | + | |
| 68 | +console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ un nombre de fichero hostil se queda en texto'); | |
| 69 | +await b.close(); | |
| 70 | +process.exit(fails ? 1 : 0); |