Files
wekan/server/lib/speedLog.js
T
Lauri Ojansivu 1d82ef8eae Security/speed/tests logging: store in the existing WeKan DB (no new files).
Per correction: use only the existing WeKan database via Meteor JavaScript
queries (works on FerretDB and MongoDB); do not create files/DBs under
WRITABLE_PATH; and have FerretDB report problems to WeKan rather than writing
itself.

- models/eventLog.js: one `eventlog` collection (stream: security|speed|tests).
- server/lib/{securityLog,speedLog,testLog}.js: thin wrappers that insert one
  document via EventLog.insertAsync (fire-and-forget, never throw).
- models/lib/securityLogFormat.js slimmed to just sanitizeDetail; remove the
  node:sqlite event store (server/lib/eventStore.js) and all file/path/schema
  helpers.
- Add a Tests stream: log anything that would fail an existing WeKan test.
- Design docs (WeKan.md, FerretDB.md) rewritten: DB-collection storage, grouped
  counts for the summary, Admin Reports read the collection, and FerretDB reports
  problems to WeKan which records them (no FerretDB DB/file writes).
- tests/securityLog.test.cjs updated (sanitizer + catalog + collection wiring +
  no-filesystem guards); verified via Python mirror.
2026-07-19 13:12:59 +03:00

40 lines
1.7 KiB
JavaScript

// ============================================================================
// WeKan speed / performance event logger (docs/Security/Remediation/WeKan.md §9)
// ----------------------------------------------------------------------------
// Records performance problems NOT auto-remediated (slow method/request,
// oversized publication, big board, repeated full scans) — and problems FerretDB
// reports back to WeKan — as documents in the existing WeKan database
// (models/eventLog.js, stream:'speed') via a normal Meteor JavaScript query.
// Best-effort, never throws. Server-only.
// ============================================================================
import EventLog from '/models/eventLog';
const { sanitizeDetail } = require('/models/lib/securityLogFormat');
// Record one performance event. Never throws.
// record({ category:'slow-method', severity:'medium', source:'ddp.method:cardsLoad',
// detail:'2.4s > 2s threshold' })
// FerretDB-reported problems use source 'ferretdb'/'sqlite.*' (WeKan saves them here).
export function record(evt = {}) {
try {
const doc = {
stream: 'speed',
at: new Date(),
severity: evt.severity || 'low',
category: evt.category || 'performance',
bleed: evt.bleed || 'SlowBleed',
action: evt.action || 'detected',
source: evt.source || '',
cwe: evt.cwe || '',
detail: sanitizeDetail(evt.detail),
};
if (evt.userId || evt.userid) doc.userId = String(evt.userId || evt.userid);
const p = EventLog.insertAsync(doc);
if (p && typeof p.catch === 'function') p.catch(() => {});
} catch (e) {
if (process.env.DEBUG === 'true') console.warn('speedLog.record failed:', e && e.message);
}
}
export default { record };