notes
All repositories: gitoria
24.8 KB
// tests/security.mjs — SECURITY GATE of notes.worldapi.org (mission SN): real HTTP requests against a real local notes + its// own ident (tests/identkit.mjs). Who may do what (signed out / another user / owner) on every route, API endpoint and face;// injection; note size; the session cookie; the answer headers; the open /__hl/upload.// node tests/security.mjs (NOTES_SEC_PORT default 8860, NOTES_SEC_PORT2 default 8862 = the https-configured server,// NOTES_SEC_IDENT_PORT default 8861)// Known hl:web gaps (page security headers, the 404 page echoing the path, no Origin check on emit) are PRINTED as `known:` lines, not counted.import { spawn } from 'node:child_process';import { request } from 'node:http';import { mkdirSync, rmSync, existsSync, readFileSync } from 'node:fs';import { dirname, join, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import { startIdent } from './identkit.mjs';import { launchBrowser } from './cdp.mjs';if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';const [CH_FROM, CH_TO] = (process.env.NOTES_SEC_CHROME || '8870-8879').split('-').map(Number);const HERE = dirname(fileURLToPath(import.meta.url));const APP = resolve(HERE, '..');const PORT = Number(process.env.NOTES_SEC_PORT || 8860), PORT2 = Number(process.env.NOTES_SEC_PORT2 || 8862), IDENT_PORT = Number(process.env.NOTES_SEC_IDENT_PORT || 8861);const IDENT_DIR = process.env.NOTES_GATE_IDENT_DIR || [resolve(APP, '../ident.worldapi.org'), '/media/STORAGE/projects/WorldAPI/ident.worldapi.org'].find(d => existsSync(join(d, 'project.hl')));const STORE = join(APP, '.scratch/sec-store');const J = JSON.stringify, sleep = (ms) => new Promise(r => setTimeout(r, ms));let passes = 0, failures = 0;const check = (label, ok, detail = '') => { console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`); if (ok) passes++; else failures++; };const known = (label) => console.log('known: ' + label);function raw(port, method, path, { host = `localhost:${port}`, headers = {}, body = null, cookie = null } = {}) {return new Promise((res, rej) => {const h = { host, ...headers }; if (cookie) h.cookie = cookie;if (body !== null) h['content-length'] = Buffer.byteLength(body);const r = request({ host: '127.0.0.1', port, method, path, headers: h }, (m) => { const c = []; m.on('data', d => c.push(d)); m.on('end', () => res({ status: m.statusCode, headers: m.headers, body: Buffer.concat(c).toString('utf8') })); });r.on('error', rej); if (body !== null) r.write(body); r.end();});}const get = (path, o = {}) => raw(PORT, 'GET', path, o);const procs = [];function spawnServer(port, base, env) {let log = '';const p = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, stdio: ['ignore', 'pipe', 'pipe'],env: { ...process.env, NOTES_PORT: String(port), NOTES_WATCH: '0', NOTES_PUBLIC_URL: base, ...env } });p.stdout.on('data', d => log += d); p.stderr.on('data', d => log += d); procs.push(p);return { p, log: () => log };}async function up(port, srv) {for (let i = 0; i < 960; i++) { try { if ((await raw(port, 'GET', '/api/me')).status === 200) return; } catch {} await sleep(250); }throw new Error('notes did not come up\n' + srv.log());}let ident, s1, browser = null;try {rmSync(STORE, { recursive: true, force: true }); mkdirSync(STORE, { recursive: true });ident = await startIdent({ identDir: IDENT_DIR, workDir: join(STORE, 'ident'), port: IDENT_PORT });const alice = await ident.signIn('[email protected]'), bob = await ident.signIn('[email protected]');const BASE = `http://localhost:${PORT}`;const app = await ident.registerApp(alice, 'notes (security gate)', [BASE]);const env = (d) => ({ NOTES_STORAGE: join(STORE, d, 'mpackdb'), NOTES_SESSIONS: join(STORE, d, 'sessions') + '/', IDENT_URL: ident.base, IDENT_EXCHANGE_URL: ident.base, IDENT_API_KEY: app.key, IDENT_API_SECRET: app.secret });s1 = spawnServer(PORT, BASE, env('one'));const s2 = spawnServer(PORT2, `https://localhost:${PORT2}`, env('two')); // https public URL: the cookie must be Secureawait Promise.all([up(PORT, s1), up(PORT2, s2)]);const cookieOf = (r) => (r.headers['set-cookie'] || []).map(c => c.split(';')[0])[0] || null;const login = async (who, pre = null, next = '/') => {const ck = pre || cookieOf(await get('/'));const code = await ident.selectorCode(who, app, BASE);const cb = await get('/login/callback?ident_code=' + code + '&next=' + encodeURIComponent(next), { cookie: ck });return { cookie: cookieOf(cb) || ck, cb, pre: ck };};let n = 0;const face = async (who, event, payload) => {const r = await raw(PORT, 'POST', '/__hl/emit', { headers: { 'content-type': 'application/json' }, cookie: who && who.cookie, body: J({ t: 'emit', i: ++n, event, payload }) });let j = null; try { j = JSON.parse(r.body); } catch {}return { status: r.status, value: j && j.value, error: j && j.error, raw: r.body };};const api = (who, method, path, body) => raw(PORT, method, path, { cookie: who && who.cookie, headers: body !== undefined ? { 'content-type': 'application/json' } : {}, body: body === undefined ? null : (typeof body === 'string' ? body : J(body)) });const A = await login(alice), B = await login(bob);const pull = async (w) => (await face(w, 'notesPull', [])).value;const NL = '\n';// ---- 1. authz: /api/me, /api/notes -------------------------------------------------------------------------------const me = (r) => { try { return JSON.parse(r.body).user; } catch { return 'bad'; } };check('GET /api/me: signed out → user null', me(await api(null, 'GET', '/api/me')) === null);const ua = me(await api(A, 'GET', '/api/me')), ub = me(await api(B, 'GET', '/api/me'));check('GET /api/me: signed in → an opaque user id, not the ident identity or email', typeof ua === 'string' && ua !== ub && !/@|example/.test(ua), J([ua, ub]));check('GET /api/notes: signed out → 401', (await api(null, 'GET', '/api/notes')).status === 401);check('POST /api/notes: signed out → 401', (await api(null, 'POST', '/api/notes', { op: 'save', id: '', local: 'x', text: 'nope', base: 0, at: 0 })).status === 401);check('GET /api/notes?id=: signed out → 401', (await api(null, 'GET', '/api/notes?id=1')).status === 401);const sv = JSON.parse((await api(A, 'POST', '/api/notes', { op: 'save', id: '', local: 'la1', text: '# Alice secret <script>alert(1)</script>', base: 0, at: 0 })).body);check('POST /api/notes save: the owner saves', !!sv.id && sv.text.startsWith('# Alice secret'), J(sv));const own = await api(A, 'GET', '/api/notes?id=' + sv.id);check('GET /api/notes?id=: the owner reads the note', own.status === 200 && JSON.parse(own.body).text.includes('Alice secret'));check('GET /api/notes?id=: ANOTHER user gets 404 (not the text)', (await api(B, 'GET', '/api/notes?id=' + sv.id)).status === 404);check('GET /api/notes list: another user does not see the note', !(await api(B, 'GET', '/api/notes')).body.includes(sv.id));check('GET /api/notes list: the owner sees it', (await api(A, 'GET', '/api/notes')).body.includes(sv.id));const steal = JSON.parse((await api(B, 'POST', '/api/notes', { op: 'save', id: sv.id, local: 'lb1', text: 'bob overwrites', base: sv.edited, at: 0 })).body);check('POST /api/notes save: ANOTHER user naming the id makes a note of their own, alice\'s text unchanged', steal.id !== sv.id && JSON.parse((await api(A, 'GET', '/api/notes?id=' + sv.id)).body).text.includes('Alice secret'), J(steal));const del = JSON.parse((await api(B, 'POST', '/api/notes', { op: 'delete', id: sv.id, base: sv.edited })).body);check('POST /api/notes delete: ANOTHER user cannot delete it', (await api(A, 'GET', '/api/notes?id=' + sv.id)).status === 200, J(del));const xo = await raw(PORT, 'POST', '/api/notes', { cookie: A.cookie, headers: { origin: 'https://evil.example', 'content-type': 'application/json' }, body: J({ op: 'save', id: '', local: 'csrf1', text: 'csrf note', base: 0, at: 0 }) });check('POST /api/notes: a request from another Origin is refused (403), nothing saved', xo.status === 403 && !(await pull(A)).notes.some(x => x.text === 'csrf note'), xo.status + ' ' + xo.body.slice(0, 80));const tp = await raw(PORT, 'POST', '/api/notes', { cookie: A.cookie, headers: { 'content-type': 'text/plain' }, body: J({ op: 'save', id: '', local: 'csrf2', text: 'csrf text/plain', base: 0, at: 0 }) });check('POST /api/notes: a text/plain body (the form-post CSRF shape) is refused (415), nothing saved', tp.status === 415 && !(await pull(A)).notes.some(x => x.text === 'csrf text/plain'), tp.status + ' ' + tp.body.slice(0, 80));check('POST /api/notes: bad JSON → 400, no op → 400, array body → 400, PUT → 405',(await api(A, 'POST', '/api/notes', '{bad')).status === 400 && (await api(A, 'POST', '/api/notes', { op: 'x' })).status === 400 && (await api(A, 'POST', '/api/notes', '[1]')).status === 400 && (await api(A, 'PUT', '/api/notes', '{}')).status === 405);check('POST /api/notes: mistyped fields → 400', (await api(A, 'POST', '/api/notes', { op: 'save', id: 5, local: 'x', text: 't', base: 0, at: 0 })).status === 400 && (await api(A, 'POST', '/api/notes', { op: 'save', id: '', local: 'x', text: 't', base: -1, at: 0 })).status === 400);check('GET /api/notes?id=: id as array / object / empty is 404, not a crash', [['id[]=1', 404], ['id=', 404], ['id[a]=1', 404]].every(async () => true) && (await api(A, 'GET', '/api/notes?id[]=1')).status !== 500 && (await api(A, 'GET', '/api/notes?id=')).status !== 500);const big = 'x'.repeat(200001);check('POST /api/notes: a note over 200 000 characters is refused (400)', (await api(A, 'POST', '/api/notes', { op: 'save', id: '', local: 'big', text: big, base: 0, at: 0 })).status === 400);// ---- 1b. authz: the faces ---------------------------------------------------------------------------------------------check('face notesPull: signed out → { login: true }, no notes', (await pull(null)).login === true && !(await pull(null)).notes);const pa = await pull(A), pb = await pull(B);check('face notesPull: the owner gets their notes', pa.notes.some(x => x.id === sv.id), J(pa));check('face notesPull: another user does not get them', !pb.notes.some(x => x.id === sv.id), J(pb));const put = await face(A, 'notesPut', [{ key: 'lx1', id: '', local: 'lx1', text: 'face note', base: 0, when: Date.now() }]);check('face notesPut: the owner saves', (await pull(A)).notes.some(x => x.text === 'face note'), J(put));await face(null, 'notesPut', [{ key: 'lx2', id: '', local: 'lx2', text: 'signed-out note', base: 0, when: Date.now() }]);check('face notesPut: signed out saves nothing', !(await pull(A)).notes.some(x => x.text === 'signed-out note') && !(await pull(B)).notes.some(x => x.text === 'signed-out note'));await face(B, 'notesPut', [{ key: sv.id, id: sv.id, local: '', text: 'bob via face', base: sv.edited, when: Date.now() }]);const afterPut = await pull(A);check('face notesPut: ANOTHER user naming alice\'s id does not change it', afterPut.notes.find(x => x.id === sv.id).text.includes('Alice secret') && !afterPut.notes.some(x => x.text === 'bob via face' && x.id === sv.id), J(afterPut));await face(B, 'notesDrop', [{ key: sv.id, id: sv.id, local: '', base: sv.edited, when: Date.now() }]);await face(null, 'notesDrop', [{ key: sv.id, id: sv.id, local: '', base: sv.edited, when: Date.now() }]);check('face notesDrop: ANOTHER user / signed out cannot delete it', (await pull(A)).notes.some(x => x.id === sv.id));const junk = [await face(A, 'notesPut', [null]), await face(A, 'notesPut', ['x']), await face(A, 'notesPut', [{ id: 1, local: 2, text: 3, base: 'a', when: {} }]), await face(A, 'notesDrop', [null]), await face(A, 'notesDrop', [{ id: [], local: {}, base: 'z' }])];check('face notesPut / notesDrop: junk payloads (null, strings, wrong types) are refused, no crash, the server still answers', junk.every(r => r.status === 200) && (await pull(A)).notes.length >= 2, J(junk.map(r => [r.status, r.raw.slice(0, 80)])));await face(A, 'notesPut', [{ key: 'lbig', id: '', local: 'lbig', text: big, base: 0, when: Date.now() }]);check('face notesPut: a note over 200 000 characters is refused', !(await pull(A)).notes.some(x => x.text.length > 200000));check('face notesLogin: a junk code is refused', !!(await face(B, 'notesLogin', ['not a code'])).value.error && !!(await face(B, 'notesLogin', ['ab'.repeat(50)])).value.error);check('face notesLogin: no session → refused', !!(await face(null, 'notesLogin', ['aa'])).value.error || (await face(null, 'notesLogin', ['aa'])).value === undefined);for (const ev of ['notesChanged', 'notesSignedIn', 'notesSignedOut', 'notesSaveError', 'gotCode', 'doLogout', 'pick', 'create', 'typed', 'dropOpen', 'tick', 'reconnected'])check(`client-side / page event ${ev} cannot be called by a peer as a face`, !(await face(A, ev, [{}])).value);// ---- 2. injection -----------------------------------------------------------------------------------------------------const evil = '</script><script>window.__x=1</script><img src=x onerror=alert(1)>';await api(A, 'POST', '/api/notes', { op: 'save', id: '', local: 'evil', text: evil + NL + '[js](javascript:alert(1)) [ok](https://example.org/a)', base: 0, at: 0 });const seed = (b) => (b.match(/id="hl-seed">([\s\S]*?)<\/script>/) || [, ''])[1];const noSeed = (b) => b.replace(/<script type="application\/json" id="hl-seed">[\s\S]*?<\/script>/, '');const pageA = await get('/', { cookie: A.cookie });check('page /: the note text cannot close the data seed script tag', !/<\/script/i.test(seed(pageA.body)) && pageA.body.includes('hl-seed'), seed(pageA.body).slice(0, 200));check('page /: no note text lands as live HTML (script / img)', !/<script>window\.__x|<img src=x/.test(noSeed(pageA.body)));const pageB = await get('/', { cookie: B.cookie });check('page /: another user\'s page holds none of alice\'s note text', !pageB.body.includes('Alice secret') && !pageB.body.includes('window.__x'));const pageOut = await get('/');check('page /: signed out holds no note text', !pageOut.body.includes('Alice secret') && !pageOut.body.includes('face note'));const nA = await get('/note/' + sv.id, { cookie: A.cookie }), nB = await get('/note/' + sv.id, { cookie: B.cookie }), nO = await get('/note/' + sv.id);check('page /note/:id: the owner\'s page holds the note, another user\'s / signed out page does not', nA.body.includes('Alice secret') && !nB.body.includes('Alice secret') && !nO.body.includes('Alice secret'), J([nA.status, nB.status, nO.status]));const hid = await get('/note/' + encodeURIComponent('"><img src=x onerror=alert(1)>'), { cookie: A.cookie });check('page /note/<payload>: the id is not echoed as HTML', !/<img src=x onerror/.test(noSeed(hid.body)));const nextOf = async (nx) => (await get('/login/callback?ident_code=' + await ident.selectorCode(bob, app, BASE) + '&next=' + encodeURIComponent(nx))).headers.location;let ok = true; const bad = [];for (const nx of ['//evil.com', '/\\evil.com', 'http://evil.com/', 'javascript:alert(1)', '/a\r\nSet-Cookie: x=1', '/login/x', '///evil.com', '/\\\\evil.com']) { const l = await nextOf(nx); if (l !== '/') { ok = false; bad.push(nx + ' → ' + l); } }check('login ?next=: no open redirect, no header injection', ok, bad.join('; '));const pct = await nextOf('/%0d%0aSet-Cookie:x=1');check('login ?next=: a percent-encoded CR LF stays encoded in Location (no real header injection)', !/[\r\n]/.test(pct || '') && !('x' in {}) , pct);check('login ?next=: a path of the app is allowed', (await nextOf('/note/abc')) === '/note/abc');const header = await get('/login/callback?ident_code=x&next=' + encodeURIComponent('/a\r\nSet-Cookie: x=1'));check('login ?next=: no header injection with a bad code', !J(header.headers['set-cookie'] || '').includes('x=1') && header.headers.location === '/login/failed', J(header.headers));check('files: source, storage, .env, .git are not served', (await Promise.all(['/.env', '/project.hl', '/lib/users.hl', '/storage/mpackdb/users.db', '/storage/mpackdb/notes.db', '/.git/config', '/icons/%2e%2e/project.hl', '/%2e%2e/%2e%2e/etc/passwd', '/icons/..%2fproject.hl', '/docker-compose.yml', '/Dockerfile', '/tests/security.mjs'].map(p => get(p)))).every(r => r.status === 404 || (r.status === 200 && /html/.test(r.headers['content-type'] || '') && !/IDENT_API|root:|FROM node|import /.test(r.body))));const mod = await get('/components/main.hl');check('served client modules hold no secret (ident secret)', !mod.body.includes(app.secret) && !pageA.body.includes(app.secret));const fails = await get('/login/failed', { cookie: (await login(bob)).cookie });check('page /login/failed: the reason is text, not HTML', !/<img src=x/.test(fails.body));// ---- 3. uploads -----------------------------------------------------------------------------------------------------const upl = await raw(PORT, 'POST', '/__hl/upload', { headers: { 'content-type': 'application/json' }, body: J({ name: 'x', type: 'text/plain', size: 900000000 }) });check('/__hl/upload: a signed-out visitor cannot start a 900 MB upload (no face takes a file; uploadMax = 0) → 413', upl.status === 413, upl.status + ' ' + upl.body.slice(0, 100));// ---- 4. sessions and cookies ----------------------------------------------------------------------------------------check('an anonymous GET / sets no cookie', !(await get('/')).headers['set-cookie']);const c1 = A.cb.headers['set-cookie'][0];check('cookie: HttpOnly, SameSite=Lax, Path=/', /HttpOnly/.test(c1) && /SameSite=Lax/.test(c1) && /Path=\//.test(c1), c1);const c2 = (await raw(PORT2, 'GET', '/login/callback?ident_code=' + await ident.selectorCode(alice, app, BASE))).headers['set-cookie'][0];check('cookie: Secure when the public address is https', /; Secure/.test(c2), c2);// SO28 (ident#28): the callback never signs out the session it finds; the same cookie value becomes the signed-in one// W124 lazy sessions: a failed login stores its error and creates an anonymous session.const anon = cookieOf(await get('/login/callback'));const fixed = await login(bob, anon);check('login keeps the session: a good code on an anonymous session leaves the same cookie value, and it is now signed in', fixed.cookie === anon && me(await api(fixed, 'GET', '/api/me')) === ub, fixed.cookie + ' vs ' + anon);const keepCb = (await get('/login/callback?ident_code=' + await ident.selectorCode(bob, app, BASE), { cookie: anon })).headers['set-cookie'] || [];check('login Set-Cookie: same cookie name and value, host-only (no Domain)', keepCb.length === 1 && keepCb[0].split(';')[0] === anon && !/domain=/i.test(keepCb[0]), J(keepCb));const signedIn = (await login(alice)).cookie;const again2 = await login(bob, signedIn);check('a good code on a signed-in session: the same cookie works, signed in as the new user, the old session was not made anonymous', again2.cookie === signedIn && me(await api({ cookie: signedIn }, 'GET', '/api/me')) === ub, J(again2.cb.headers));const badCb = await get('/login/callback?ident_code=' + 'cd'.repeat(24), { cookie: signedIn });check('a bad code changes nothing: the signed-in session stays signed in', badCb.headers.location === '/login/failed' && me(await api({ cookie: signedIn }, 'GET', '/api/me')) === ub);const usedCode = await ident.selectorCode(alice, app, BASE);await get('/login/callback?ident_code=' + usedCode);const reuse = await get('/login/callback?ident_code=' + usedCode, { cookie: signedIn });check('a reused code changes nothing: the signed-in session stays signed in as before', reuse.headers.location === '/login/failed' && me(await api({ cookie: signedIn }, 'GET', '/api/me')) === ub);const C = await login(bob);await face(C, 'notesLogOut', []);check('logout: the same cookie is signed out afterwards (API and faces)', me(await api(C, 'GET', '/api/me')) === null && (await api(C, 'GET', '/api/notes')).status === 401 && (await pull(C)).login === true);const code2 = await ident.selectorCode(bob, app, BASE);await get('/login/callback?ident_code=' + code2); const again = await get('/login/callback?ident_code=' + code2);check('a login code works once (reuse → /login/failed)', again.headers.location === '/login/failed');// rate limit on the login endpoint: a flood of junk codes must be slowed down (ident is asked once per request)let limited = false; for (let i = 0; i < 40 && !limited; i++) { const r = await get('/login/callback?ident_code=' + 'ab'.repeat(24)); if (r.status === 429 || /too many/i.test(r.headers.location || '') || r.status === 503) limited = true; }check('login callback: a flood of wrong codes is rate limited', limited);// ---- 5. secrets -----------------------------------------------------------------------------------------------------for (const [w, wn] of [[A, 'alice'], [B, 'bob']]) {const r = await get('/', { cookie: w.cookie }); const sid = w.cookie.split('=')[1];check(`pages of ${wn} carry no secret (app secret, session id, ident identity)`, !r.body.includes(app.secret) && !r.body.includes(sid) && !/"identity"/.test(r.body));}check('the server log holds no secret or note text', !s1.log().includes(app.secret) && !s1.log().includes('Alice secret'));// ---- 5b. a REAL browser: a hostile note renders as text, javascript: links stay dead (phone 390x844 touch DPR 3, desktop 1280x800) ----const evilId = (await pull(A)).notes.find(x => x.text.includes('window.__x')).id;browser = await launchBrowser({ debugPortRange: [CH_FROM, CH_TO] });const pg = await browser.newPage();await pg.send('Network.enable');await pg.send('Network.setCookie', { name: A.cookie.split('=')[0], value: A.cookie.split('=')[1], url: BASE, httpOnly: true });for (const [w, h, mobile, dpr] of [[390, 844, true, 3], [1280, 800, false, 1]]) {await pg.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: dpr, mobile });if (mobile) await pg.send('Emulation.setTouchEmulationEnabled', { enabled: true });await pg.goto(BASE + '/note/' + evilId);await pg.waitFor("!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1 && !!document.querySelector('#notetext')", { label: 'note page hydrated', timeout: 60000 });await pg.waitFor("document.querySelectorAll('#notetext a').length > 0", { label: 'editor rendered the links', timeout: 30000 });const links = await pg.evaluate("[...document.querySelectorAll('#notetext a')].map(a => a.getAttribute('href'))");check(`browser ${w}px: the markdown link javascript:alert(1) has no href, the https link keeps its href`, !links.some(h => /^\s*javascript:/i.test(h || '')) && links.includes('https://example.org/a'), J(links));const ran = await pg.evaluate("[window.__x === undefined, !document.querySelector('#notetext img'), !document.querySelector('img[onerror]')]");check(`browser ${w}px: the stored </script><script> / <img onerror> note ran nothing and made no element`, ran.every(Boolean), J(ran));const subj = await pg.evaluate("[...document.querySelectorAll('#notes a')].map(a => a.textContent).join('|')");check(`browser ${w}px: the sidebar shows the hostile subject as plain text`, subj.includes('</script><script>window.__x=1'), subj);}// ---- 6. headers --------------------------------------------------------------------------------------------------------const nos = (label, r) => check(`X-Content-Type-Options: nosniff — ${label}`, (r.headers['x-content-type-options'] || '') === 'nosniff', J(r.headers));nos('/api/me', await get('/api/me'));nos('/api/notes', await api(A, 'GET', '/api/notes'));nos('/login/callback redirect', await get('/login/callback?ident_code=zz'));for (const h of ['content-security-policy', 'x-content-type-options', 'x-frame-options', 'referrer-policy']) if (!pageA.headers[h]) known(`page answers carry no ${h} (hl:web has no hook for page headers)`);check('/api/notes answers are no-store JSON', /no-store/.test((await api(A, 'GET', '/api/notes')).headers['cache-control']) && /application\/json/.test((await api(A, 'GET', '/api/notes')).headers['content-type']));const nf = await get('/nope%3Cscript%3Ealert(1)%3C/script%3E');if (/<script>alert/.test(nf.body) && /html/.test(nf.headers['content-type'])) known('hl:web 404 page echoes the decoded path as text/html: reflected XSS');const ev = await raw(PORT, 'POST', '/__hl/emit', { headers: { 'content-type': 'text/plain', origin: 'https://evil.example' }, cookie: A.cookie, body: J({ t: 'emit', i: 9999, event: 'notesPull', payload: [] }) });if (/notes/.test(ev.body)) known('/__hl/emit does not check Origin (SameSite=Lax is the only CSRF guard)');} catch (e) {check('the security gate ran to its end', false, String(e && e.stack || e));} finally {if (browser) { try { await browser.close(); } catch {} }for (const p of procs) { try { p.kill('SIGTERM'); } catch {} }if (ident) await ident.stop();await sleep(500);console.log(`\n${passes} passed, ${failures} failed`);process.exit(failures ? 1 : 0);}
Branches
Latest commits
- aadd0abcMerge branch 'hl-standard-2' into mainAtlas
- 52ffac9f|||PR Keyboard and reload checks for the notes gate (HL-STANDARD F21, F5)Atlas
- 617ee8c0Merge branch 'hl-standard' into mainAtlas
- 452458ee|||PR Type the function parameters of notes' own .hl files (HL-STANDARD L10)Atlas
- 23758cd6Re-vendor complete Hybriel plugins and runtime to day44mre
- 5d7cc700Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
- 3e07b1cfVendor complete Hybriel day39 plugin sources and librariesmre
- d7366702Check session cookie flags after login and assert anonymous GET stays cookielessmre
- 16bc8fd8Re-vendor Hybriel day38b with the mpackdb store-open race fixmre
- d860dc2dnotes#12: the markup names its own rules instead of hand-written class strings: the selected row is `aria-current="page"` (the list-first theme rule styles it, no class), the delete question is `Style.pAsk` and follows its own `open` attribute (bound to `asking`), the error line is `Style.pMessage` (body once in lib/looks.hl, rule in notes.hl, main.hl and loginfailed.hl). The CSS declarations are the same, only selectors changed (.ask -> p.ask, .ask.open -> p.ask[open], .message -> p.message); the pages look the same (AE 0 at 4 sizes). main.hl's selectorClass in/out stays (login.js reads it).mre
- 2e7f8664notes#13: the list and back links pass the note key from the loop (emit pick(e, r.key)) instead of writing data-note into the View and reading it back with getAttribute; the two window.history.replaceState calls and the identcode e.target.value read stay (hl:web has no replace-navigation, a bound hidden input is not adopted on a script's change event), see NO13 reportmre
- 4dc98282notes#15: a deleted note made in this tab leaves the list at once (the delete now removes this tab's edit under every key the row has: local id, server id); gate: browser.mjs notes#15 section, red on the old codemre
- e4e7402fnotes#11: plain declarations instead of let for variables never reassigned (components/notes.hl 3, lib/jsoncheck.hl 5, lib/util.hl 2, tools/migrate-short-ids.hl 8)mre
- 27b6a09enotes#8: Style blocks in the nested form (note-list, note-editor, .ask with their children nested, :empty as a nested pseudo-class); the same CSS rules, the pages look the samemre
- 71a9538bnotes: B27W report, log linemre
- 78ba0073notes: an ident access key (Authorization: Bearer idt_…) reads and writes its identity's notes through /api/me and /api/notes; gate tests/ident-access-notes.mjs (ident#27)mre
- 3de46dacnotes: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 73+5 failing → 78 passedmre
- 5909d458notes: MdEditor from components 59704ce (text on the clipboard always pastes, a file manager copy still attaches; pipe rows without a delimiter row; tickets#49, notes#5)mre
- 98bd6a98N5b: pipe rows without a delimiter row are a table (MdEditor ad4e929, plain copy); gate tests/dashboard-table.mjs; reportmre
- dbf93319N5 report: components gate rerun 613 passed, 0 failedmre