Initial upload to Gitea
This commit is contained in:
1 parent
78193254ad
commit
8478998cae
1485 files changed
+461025
-42348
No files matched your search
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
|
||||
// Automated guard for the branding/avatar HTML sink escapes in
|
||||
// public/js/bot.js.
|
||||
//
|
||||
// Eight innerHTML template sinks interpolate values an operator or account
|
||||
// controls (BRAND_NAME / BRAND_LOGO via the branding settings, userAvatarSrc
|
||||
// from the account profile). They were wrapped in escapeHtml() by hand in the
|
||||
// multi-fix security pass, but no automated guard existed — a future template
|
||||
// edit could silently revert a wrap and re-open a stored-XSS sink rendered to
|
||||
// every user of the bot page. This file pins each of the eight sites, with
|
||||
// exact occurrence counts (so copying a template without its wrap cannot slip
|
||||
// through), and asserts that no unescaped src="${...}" interpolation of the
|
||||
// same values remains.
|
||||
//
|
||||
// Same source-window convention as the other bot.js tests in this directory:
|
||||
// read the file with fs and assert on the source. public/js/bot.js ships
|
||||
// unminified and there is no bot.min.js to keep in sync.
|
||||
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert");
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
const ROOT = path.join(__dirname, "..");
|
||||
|
||||
const BOT_SRC = fs.readFileSync(path.join(ROOT, "public", "js", "bot.js"), "utf8");
|
||||
|
||||
function countOccurrences(haystack, needle) {
|
||||
let count = 0;
|
||||
let at = haystack.indexOf(needle);
|
||||
while (at !== -1) {
|
||||
count += 1;
|
||||
at = haystack.indexOf(needle, at + needle.length);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
function assertExactCount(needle, expected, label) {
|
||||
const got = countOccurrences(BOT_SRC, needle);
|
||||
assert.strictEqual(
|
||||
got,
|
||||
expected,
|
||||
`${label}: expected ${expected} occurrence(s) of ${JSON.stringify(needle)}, found ${got}`
|
||||
);
|
||||
}
|
||||
|
||||
test("planner 'Send to <brand> Agent' tooltips escape BRAND_NAME (2 sites)", () => {
|
||||
assertExactCount('title="Send to ${escapeHtml(BRAND_NAME)} Agent"', 2, "planner item + action send buttons");
|
||||
// The unescaped shape must not exist in any tooltip.
|
||||
assert.strictEqual(countOccurrences(BOT_SRC, 'title="Send to ${BRAND_NAME}'), 0);
|
||||
});
|
||||
|
||||
test("AI avatar <img> sources escape BRAND_LOGO and userAvatarSrc (4 sites)", () => {
|
||||
assertExactCount('src="${escapeHtml(BRAND_LOGO)}"', 3, "AI message / typing / agent avatars");
|
||||
assertExactCount('src="${escapeHtml(userAvatarSrc)}"', 1, "user avatar");
|
||||
assert.strictEqual(
|
||||
countOccurrences(BOT_SRC, 'src="${BRAND_LOGO}'),
|
||||
0,
|
||||
"unescaped BRAND_LOGO <img> src must not remain"
|
||||
);
|
||||
assert.strictEqual(
|
||||
countOccurrences(BOT_SRC, 'src="${userAvatarSrc}'),
|
||||
0,
|
||||
"unescaped userAvatarSrc <img> src must not remain"
|
||||
);
|
||||
});
|
||||
|
||||
test("AI agent approval/question titles escape BRAND_NAME (2 sites)", () => {
|
||||
assertExactCount("${escapeHtml(BRAND_NAME)} Agent wants to:", 1, "agent approval title");
|
||||
assertExactCount("${escapeHtml(BRAND_NAME)} Agent asks:", 1, "agent question title");
|
||||
});
|
||||
Reference in new issue
Block a user