Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
115 lines
3.9 KiB
JavaScript
115 lines
3.9 KiB
JavaScript
"use strict";
|
|
|
|
const assert = require("node:assert/strict");
|
|
const test = require("node:test");
|
|
const {
|
|
detectSpamComment,
|
|
extractDangerousFiles,
|
|
extractZipFiles,
|
|
isGitHubUserAttachment,
|
|
} = require("./spam-comment-filter.cjs");
|
|
|
|
test("flags the fake Netcatty patch spam pattern", () => {
|
|
const result = detectSpamComment({
|
|
authorAssociation: "NONE",
|
|
userType: "User",
|
|
body: "[netcatty_patch.zip](https://example.com/netcatty_patch.zip)\n\nMan, that terminal rendering bug is such a pain. It looks like the sftp module is tripping over the encoding when it tries to sync the current path. I found a quick patch that fixes the character mapping in the backend so those black boxes finally disappear.",
|
|
});
|
|
|
|
assert.equal(result.spam, true);
|
|
});
|
|
|
|
test("flags fake patch spam when the filename ends a sentence", () => {
|
|
const result = detectSpamComment({
|
|
authorAssociation: "NONE",
|
|
userType: "User",
|
|
body: "Download this patch.zip. It fixes the backend encoding so the terminal rendering black boxes disappear.",
|
|
});
|
|
|
|
assert.equal(result.spam, true);
|
|
assert.deepEqual(result.dangerousFiles, ["patch.zip"]);
|
|
});
|
|
|
|
test("flags any zip from an outside user, including hash-named soft bait", () => {
|
|
const result = detectSpamComment({
|
|
authorAssociation: "NONE",
|
|
userType: "User",
|
|
body: "[63bf1862b52422e38b8cb170.zip](https://github.com/user-attachments/files/29784176/63bf1862b52422e38b8cb170.zip)\nI'd start with the docs inside",
|
|
});
|
|
|
|
assert.equal(result.spam, true);
|
|
assert.ok(
|
|
result.dangerousFiles.some((file) => file.includes("63bf1862b52422e38b8cb170.zip"))
|
|
);
|
|
});
|
|
|
|
test("flags ordinary zip log attachments from outside users", () => {
|
|
const result = detectSpamComment({
|
|
authorAssociation: "FIRST_TIME_CONTRIBUTOR",
|
|
userType: "User",
|
|
body: "[debug-logs.zip](https://github.com/user-attachments/files/29784176/debug-logs.zip)\nI attached logs from a failed connection. The app hangs after I click connect, and the logs show the SSH handshake timing out.",
|
|
});
|
|
|
|
assert.equal(result.spam, true);
|
|
});
|
|
|
|
test("flags other dangerous archives from outside users", () => {
|
|
const result = detectSpamComment({
|
|
authorAssociation: "NONE",
|
|
userType: "User",
|
|
body: "See hotfix.dmg for the workaround.",
|
|
});
|
|
|
|
assert.equal(result.spam, true);
|
|
assert.deepEqual(result.dangerousFiles, ["hotfix.dmg"]);
|
|
});
|
|
|
|
test("does not flag trusted maintainers even when sharing zip archives", () => {
|
|
const result = detectSpamComment({
|
|
authorAssociation: "OWNER",
|
|
userType: "User",
|
|
body: "Try this temporary netcatty_patch.zip while I prepare the signed release. It fixes the rendering issue.",
|
|
});
|
|
|
|
assert.equal(result.spam, false);
|
|
});
|
|
|
|
test("does not flag bot comments that mention zip files", () => {
|
|
const result = detectSpamComment({
|
|
authorAssociation: "NONE",
|
|
userType: "Bot",
|
|
body: "Uploaded build-artifacts.zip for CI.",
|
|
});
|
|
|
|
assert.equal(result.spam, false);
|
|
});
|
|
|
|
test("does not flag comments without downloadable archives", () => {
|
|
const result = detectSpamComment({
|
|
authorAssociation: "NONE",
|
|
userType: "User",
|
|
body: "I attached screenshots of the hang after connect. The SSH handshake times out.",
|
|
});
|
|
|
|
assert.equal(result.spam, false);
|
|
});
|
|
|
|
test("extracts risky file names from markdown links and plain text", () => {
|
|
assert.deepEqual(
|
|
extractDangerousFiles("[fix.zip](https://example.com/fix.zip) also hotfix.dmg."),
|
|
["fix.zip", "https://example.com/fix.zip", "hotfix.dmg"]
|
|
);
|
|
assert.deepEqual(extractZipFiles("[fix.zip](https://example.com/fix.zip) also hotfix.dmg."), [
|
|
"fix.zip",
|
|
"https://example.com/fix.zip",
|
|
]);
|
|
});
|
|
|
|
test("identifies GitHub user attachment URLs", () => {
|
|
assert.equal(
|
|
isGitHubUserAttachment("https://github.com/user-attachments/files/29784176/netcatty_fix.zip"),
|
|
true
|
|
);
|
|
assert.equal(isGitHubUserAttachment("https://example.com/netcatty_fix.zip"), false);
|
|
});
|