mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 09:45:04 -05:00
"Are the security tests enough to prevent what is in the Hall of Fame" was unanswerable. WeKan publishes 58 named vulnerabilities at https://wekan.fi/hall-of-fame/ ; some suites name the one they belong to, most did not, and the Hall of Fame lives in a different repository that CI never checks out. Answering it meant reading 58 pages against 300 suites by hand, which means it was never answered - and a regression test that quietly stops existing is worth nothing, the failure mode tests/testsAreRegistered.test.cjs already caught once when two *bleed suites drifted out of the mocha index. So the list lives in the repository that has the tests, and tests/securityRegressionCoverage.test.cjs keeps the two in step. Every published vulnerability is either GUARDED - named by a suite that still exists - or RECORDED, a gap with a written reason, which is the CHANGELOG's "TODO Later" pattern applied to tests. The gap count is pinned, so a vulnerability cannot be published with neither a test nor a note; a gap that turns out to be guarded after all fails too, so coverage is never understated; and a file that merely REGISTERS suites is not accepted as coverage, or the guard would pass itself. Getting there meant naming vulnerabilities in the suites that already guarded them, which is most of what this commit is: - tests/securityMeifukun.test.cjs guards eight reports and named one. Its sections are RedirectBleed, SourceBleed, LiveBleed, CasBleed, OidcBleed, MetricsBleed, ImpersonateBleed and InviteBleed - seven vulnerabilities that looked untested and were not. - tests/noIdentityReplacement.test.cjs guards IdentityBleed and PatternBleed, the same CodeQL finding twice. - ExportBleed, CrashBleed, MimeBleed and the four LockoutBleed suites now say so. - tests/crossBoardParentCardLeak.test.cjs also guards BoardBleed's cross-board move deny, and now checks it on Lists and Swimlanes too, not only Cards. The count that comes out of it: 29 of 58 published vulnerabilities have a named regression test, and 29 are recorded gaps - mostly older fixes from before WeKan tested its security fixes at all. They are not known to be unprotected; they are known to be unchecked, which is a different and more honest statement, and each one now says what it would take to close it. Thanks to xet7 !
97 lines
4.5 KiB
JavaScript
97 lines
4.5 KiB
JavaScript
'use strict';
|
|
|
|
// ExportBleed - https://wekan.fi/hall-of-fame/exportbleed/
|
|
// Named for tests/securityRegressionCoverage.test.cjs, which checks the published
|
|
// Hall of Fame list against the tests that guard it - a test that does not say
|
|
// which vulnerability it belongs to cannot be checked against that list.
|
|
|
|
// Regression for GHSA-8r5p-4q9j-f5jx: Stored XSS in HTML board exports through a
|
|
// card-title second parse.
|
|
//
|
|
// The exported index.html embeds a click handler that opens a per-card modal. It
|
|
// read the card title/body via .textContent (which DECODES HTML entities) and then
|
|
// concatenated those values into `content.innerHTML` — a SECOND parse that revived
|
|
// entity-encoded markup (e.g. a card titled `<img src=x onerror=...>`) and
|
|
// executed it when a recipient clicked the card in the export. The fix builds the
|
|
// modal with DOM nodes and assigns the title/body through textContent, never
|
|
// innerHTML.
|
|
//
|
|
// exportHTML.js is a Blaze/ESM client module, so this guards the SOURCE of the
|
|
// injected handler: the untrusted values (titleText/allText) must reach only
|
|
// textContent, and must never be concatenated into an innerHTML assignment.
|
|
// Run: node tests/exportHTMLXss.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
let passed = 0;
|
|
function check(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
|
|
const src = fs.readFileSync(
|
|
path.join(__dirname, '..', 'client', 'lib', 'exportHTML.js'), 'utf8');
|
|
|
|
check('the card title/body are inserted via textContent (inert), not innerHTML', () => {
|
|
assert.ok(/titleEl\.textContent = titleText/.test(src),
|
|
'the card title must be assigned through textContent');
|
|
assert.ok(/bodyEl\.textContent = allText/.test(src),
|
|
'the card body must be assigned through textContent');
|
|
});
|
|
|
|
check('titleText / allText never reach an innerHTML assignment (the second parse)', () => {
|
|
// Every `X.innerHTML = ...` assignment in the file must not include the
|
|
// entity-decoded card values on its right-hand side.
|
|
const innerHtmlAssigns = src.match(/\.innerHTML\s*=\s*[^\n;]+/g) || [];
|
|
for (const line of innerHtmlAssigns) {
|
|
assert.ok(!/titleText|allText/.test(line),
|
|
`titleText/allText must not flow into innerHTML: ${line}`);
|
|
}
|
|
});
|
|
|
|
check('the old vulnerable concatenation is gone', () => {
|
|
assert.ok(!/content\.innerHTML\s*=\s*'<h2[^\n]*titleText/.test(src),
|
|
'the h2/allText innerHTML concatenation must be removed');
|
|
// The close button is now built as a DOM node, not modal.innerHTML.
|
|
assert.ok(!/modal\.innerHTML\s*=/.test(src),
|
|
'the modal must not be built via innerHTML');
|
|
});
|
|
|
|
check('the handler clears the modal safely and appends DOM nodes', () => {
|
|
assert.ok(/while \(modal\.firstChild\)/.test(src), 'modal is cleared via DOM removal, not innerHTML=""');
|
|
assert.ok(/document\.createElement\('h2'\)/.test(src) && /modal\.appendChild\(content\)/.test(src),
|
|
'the modal content is built from DOM nodes');
|
|
});
|
|
|
|
// Behavioural check of the core property against a minimal DOM: an entity-decoded
|
|
// title containing a live tag, when assigned via textContent, must NOT create child
|
|
// elements (no second parse); if it were assigned via innerHTML it would.
|
|
check('textContent assignment does not revive an entity-decoded <img> (unlike innerHTML)', () => {
|
|
// Minimal element stub mimicking the DOM contract used by the fix.
|
|
function makeEl() {
|
|
const el = { children: [], _text: '', style: {}, appendChild(c) { this.children.push(c); return c; } };
|
|
Object.defineProperty(el, 'textContent', {
|
|
get() { return this._text; },
|
|
set(v) { this._text = String(v); /* textContent never parses children */ },
|
|
});
|
|
Object.defineProperty(el, 'innerHTML', {
|
|
get() { return this._html || ''; },
|
|
set(v) {
|
|
this._html = String(v);
|
|
// A real browser would parse markup into children on innerHTML=.
|
|
if (/<img|<script|onerror=/i.test(this._html)) this.children.push({ tag: 'parsed-markup' });
|
|
},
|
|
});
|
|
return el;
|
|
}
|
|
const decodedMaliciousTitle = '<img src=x onerror="alert(1)">'; // what .textContent decodes to
|
|
const titleEl = makeEl();
|
|
titleEl.textContent = decodedMaliciousTitle;
|
|
assert.strictEqual(titleEl.children.length, 0, 'textContent must not parse markup into elements');
|
|
// Control: the previously-vulnerable innerHTML path WOULD have parsed it.
|
|
const bad = makeEl();
|
|
bad.innerHTML = '<h2>' + decodedMaliciousTitle + '</h2>';
|
|
assert.ok(bad.children.length > 0, 'sanity: innerHTML would have revived the tag');
|
|
});
|
|
|
|
console.log(`\nexportHTMLXss: ${passed} checks passed`);
|