Files
wekan/models/lib/impersonationReportQuery.js
T
Lauri Ojansivu 339729fd95 Tests for newest Security/Reports features (positive + negative)
- client/lib/tests/renderLinksPlainText.tests.js: the 'render links as plain text'
  toggle and XSS hardening. Config assertions (stripLinks adds <a> to FORBID_TAGS,
  default does not, KEEP_CONTENT) plus real sanitizeHTML() behavior: <a> stripped to
  its text when stripLinks, kept by default, and javascript: hrefs / event handlers /
  <script> removed regardless.
- client/lib/tests/alwaysShowCodeAsText.tests.js: escapeHtmlSource (exposed on the
  Markdown export) escapes <script>/comments/quotes/ampersand-first so code is shown
  not executed; leaves plain text and empty strings unchanged.
- server/lib/tests/impersonationReportQuery.tests.js: the Impersonation report search
  selector (extracted to models/lib/impersonationReportQuery.js so it is testable
  without re-registering the publication) builds a case-insensitive $or across the
  identity fields, escapes regex metacharacters, and is empty for a blank term.

The MimeBleed fix (fileValidationBypass.security.tests.js), SortBleed
(boards.security.tests.js) and import/export anonymization
(importExportSecurity.tests.js) already carry positive + negative tests.
2026-07-14 17:01:35 +03:00

21 lines
808 B
JavaScript

// Pure, Meteor-free helper for the Admin Panel / Reports / Impersonation report.
// Builds the Mongo selector that matches a search term (if any) against the
// admin/user/board/attachment ids and the reason, case-insensitively. Kept in its
// own module so it can be unit-tested without importing the publication (which
// would re-register the 'impersonationReport' publish and throw).
export function impersonationQuery(searchTerm) {
const query = {};
if (searchTerm) {
// Escape regex metacharacters so a search term is matched literally.
const rx = new RegExp(String(searchTerm).replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i');
query.$or = [
{ adminId: rx },
{ userId: rx },
{ boardId: rx },
{ attachmentId: rx },
{ reason: rx },
];
}
return query;
}