Skip to content

Open-source, local-first social media research agent for Instagram, TikTok, and LinkedIn. Jev routes read-only steps; socai CLI captures cited browser evidence.

fix: resolve initial CodeQL findings

Asklvd7e56feb92d0
diff --git a/src/actions.js b/src/actions.js
index 832a037..dd6e805 100644
--- a/src/actions.js
+++ b/src/actions.js
@@ -127,7 +127,7 @@ export function availableActions({ platform, query, goal, items, history, comman
}
// An explicit user-supplied URL is also a valid starting point.
for (const raw of goal.match(/https:\/\/[^\s<>"']+/g) || []) {
- const url = sourceUrl(raw.replace(/[.,;)]+$/, ""), platform);
+ const url = sourceUrl(stripTrailingUrlPunctuation(raw), platform);
if (url && targetKind(url, platform)) targets.set(url, {});
}
for (const [target, item] of targets) {
@@ -153,6 +153,12 @@ export function availableActions({ platform, query, goal, items, history, comman
return actions;
}
+function stripTrailingUrlPunctuation(value) {
+ let end = value.length;
+ while (end > 0 && ".,;)".includes(value[end - 1])) end -= 1;
+ return value.slice(0, end);
+}
+
export async function chooseAction({ goal, platform, actions, history, items, limit, remainingSteps, ...options }) {
if (!actions.length) throw new AppError("No supported actions are available.", { code: "NO_ACTIONS" });
const request = {
diff --git a/src/query.js b/src/query.js
index 79e76ba..f477c2b 100644
--- a/src/query.js
+++ b/src/query.js
@@ -44,7 +44,8 @@ export function extractSearchQuery(request) {
function cleanTopic(value) {
return value
.trim()
- .replace(/^["'“‘]+|["'”’]+$/g, "")
+ .replace(/^["'“‘]+/, "")
+ .replace(/["'”’]+$/, "")
.replace(/\s+please$/i, "")
.replace(/[。.!??]+$/g, "")
.trim();
diff --git a/src/report.js b/src/report.js
index 6380eed..2516d41 100644
--- a/src/report.js
+++ b/src/report.js
@@ -241,7 +241,7 @@ export function validateResearchReport(report, items = []) {
const records = sourceRecords(publicEvidence(items)).slice(0, MAX_REPORT_SOURCES);
const expectedById = new Map(records.map(({ url }, index) => [`E${index + 1}`, url]));
const allowed = new Set(expectedById.values());
- const reportUrls = [...text.matchAll(/https?:\/\/[^\s)\]|>]+/g)].map(([url]) => url.replace(/[.,;]+$/, ""));
+ const reportUrls = [...text.matchAll(/https?:\/\/[^\s)\]|>]+/g)].map(([url]) => stripTrailingUrlPunctuation(url));
for (const url of reportUrls) {
if (!allowed.has(url)) errors.push(`Report cites a URL that is not a captured source: ${url}.`);
}
@@ -501,7 +501,13 @@ function inline(value) {
}
function table(value, max = 90) {
- return inline(truncate(String(value || ""), max)).replace(/\|/g, "\\|");
+ return inline(truncate(String(value || ""), max));
+}
+
+function stripTrailingUrlPunctuation(value) {
+ let end = value.length;
+ while (end > 0 && ".,;".includes(value[end - 1])) end -= 1;
+ return value.slice(0, end);
}
function truncate(value, max) {
diff --git a/src/socai.js b/src/socai.js
index c0db557..02497e9 100644
--- a/src/socai.js
+++ b/src/socai.js
@@ -490,7 +490,6 @@ function isPathLike(val) {
/^~[/\\]/.test(decoded) ||
/^\.{1,2}[/\\]/.test(decoded) ||
/^[/\\](?![/\\])[^/?#\\]+(?:[/\\][^/?#\\]+)*$/.test(decoded) ||
- /^\/(?!\/)[^/?#]+(?:[/\\][^/?#]+)*$/.test(decoded) ||
/^\/(?:Users|home|root|tmp|var|opt|usr|etc|Volumes|private|mnt|media|srv|dev|proc|sys)\b/i.test(decoded) ||
/^(?:\/[a-zA-Z0-9._~-]+){2,}/.test(decoded) ||
/^[/\\]{2}/.test(decoded) ||
diff --git a/test-support/text.js b/test-support/text.js
new file mode 100644
index 0000000..de98fc2
--- /dev/null
+++ b/test-support/text.js
@@ -0,0 +1,33 @@
+export function stripMarkup(value, separator = "") {
+ const source = String(value ?? "");
+ let output = "";
+ let insideTag = false;
+ for (const character of source) {
+ if (!insideTag && character === "<") {
+ insideTag = true;
+ output += separator;
+ continue;
+ }
+ if (insideTag) {
+ if (character === ">") insideTag = false;
+ continue;
+ }
+ output += character;
+ }
+ return output;
+}
+
+export function markdownLinkTargets(value) {
+ const source = String(value ?? "");
+ const targets = [];
+ let cursor = 0;
+ while (cursor < source.length) {
+ const start = source.indexOf("](", cursor);
+ if (start < 0) break;
+ const end = source.indexOf(")", start + 2);
+ if (end < 0) break;
+ targets.push(source.slice(start + 2, end));
+ cursor = end + 1;
+ }
+ return targets;
+}
diff --git a/test/actions.test.js b/test/actions.test.js
index 3ba7f7f..018818a 100644
--- a/test/actions.test.js
+++ b/test/actions.test.js
@@ -17,6 +17,12 @@ test('actions accept only observed social targets and known CLI operations', ()
assert.ok(!availableActions({...base,commands:['search']}).some(x=>x.kind==='page_state'));
});
+test('explicit goal URLs trim trailing prose punctuation without changing the target', () => {
+ const actions=availableActions({...base,goal:'Inspect https://www.instagram.com/p/safe/)));.,',items:[]});
+ const read=actions.find((action)=>action.kind==='read_post');
+ assert.equal(read?.target,'https://www.instagram.com/p/safe/');
+});
+
test('TikTok media downloads require explicit user intent', () => {
const tiktok={platform:'tiktok',query:'handmade art',goal:'research handmade art on TikTok',items:[{url:'https://www.tiktok.com/@demo/video/222',title:'Handmade art'}],history:[],commands:['search','get-videos','author','page_state'],limit:4};
assert.ok(!availableActions(tiktok).some(x=>x.downloadMedia));
diff --git a/test/distribution-docs.test.js b/test/distribution-docs.test.js
index 079d5e8..4850c1a 100644
--- a/test/distribution-docs.test.js
+++ b/test/distribution-docs.test.js
@@ -3,6 +3,8 @@ import { execFileSync } from "node:child_process";
import { access, readFile, readdir } from "node:fs/promises";
import test from "node:test";
+import { markdownLinkTargets, stripMarkup } from "../test-support/text.js";
+
const packageJson = JSON.parse(
await readFile(new URL("../package.json", import.meta.url), "utf8"),
);
@@ -61,7 +63,7 @@ function normalizedVisibleText(contents) {
const attributeValues = [...contents.matchAll(/\b(?:aria-label|content|title)="([^"]*)"/gi)]
.map((match) => match[1])
.join(" ");
- return `${contents.replace(/<[^>]*>/g, " ")} ${attributeValues}`
+ return `${stripMarkup(contents, " ")} ${attributeValues}`
.replace(/&(?:nbsp|ensp|emsp|thinsp|hyphen|ndash|mdash);/gi, " ")
.replace(/&#(?:x[a-f\d]+|\d+);/gi, " ")
.replace(/\s+/g, " ")
@@ -103,8 +105,7 @@ function extractKevCommands(contents) {
"uv sync --extra serve",
"uv run --extra serve python -m kev.serve ",
];
- return contents
- .replace(/<[^>]*>/g, "")
+ return stripMarkup(contents)
.split(/\r?\n/)
.map((line) => line.trim())
.filter((line) => prefixes.some((prefix) => line.startsWith(prefix)));
@@ -121,8 +122,7 @@ function extractSimpleJevCommands(contents) {
"python hf-server/hf_server.py ",
"curl --fail http://127.0.0.1:8000/health",
];
- return contents
- .replace(/<[^>]*>/g, "")
+ return stripMarkup(contents)
.split(/\r?\n/)
.map((line) => line.trim())
.filter((line) => prefixes.some((prefix) => line.startsWith(prefix)));
@@ -280,7 +280,7 @@ test("the Pages landing exposes current structured metadata and recorded evidenc
assert.equal(software.softwareVersion, packageJson.version);
assert.equal(software.codeRepository, "https://github.com/socai-io/jev-social");
assert.equal(software.offers?.price, "0");
- assert.ok(software.sameAs?.includes("https://ossdrop.com/tool/jev-social"));
+ assert.ok(software.sameAs?.some((url) => url === "https://ossdrop.com/tool/jev-social"));
for (const expected of [
"docs/example-report.md",
@@ -326,12 +326,9 @@ test("the README keeps Jev Social promotion separate from the socai runtime", as
],
);
assert.match(readme, /On Linux,[^.]+(?:PATH|SOCAI_BIN)[^.]+onboarding\./);
- assert.ok(readme.includes(
- '[good first issues](https://github.com/socai-io/jev-social/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22good%20first%20issue%22)',
- ));
- assert.ok(readme.includes(
- "[CONTRIBUTING.md](https://github.com/socai-io/jev-social/blob/main/CONTRIBUTING.md)",
- ));
+ const readmeTargets = markdownLinkTargets(readme);
+ assert.ok(readmeTargets.some((url) => url === "https://github.com/socai-io/jev-social/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22good%20first%20issue%22"));
+ assert.ok(readmeTargets.some((url) => url === "https://github.com/socai-io/jev-social/blob/main/CONTRIBUTING.md"));
assert.doesNotMatch(
readme,
/https?:\/\/(?:www\.)?github\.com\/socai-io\/socai(?:\.git)?(?=$|[\s/?#)"'<])/i,
@@ -346,18 +343,13 @@ test("the README distinguishes an ecosystem catalog copy from a related workflow
const ecosystem = markdownH2Section(readmeContents, "Ecosystem");
assert.ok(ecosystem, "the README must expose the ecosystem catalog copy");
- assert.ok(ecosystem.includes(
- "https://github.com/davepoon/buildwithclaude/tree/5864a032c1656350343fa982246ca9ffdd889c34/plugins/all-skills/skills/jev-social",
- ));
+ const ecosystemTargets = markdownLinkTargets(ecosystem);
+ assert.ok(ecosystemTargets.some((url) => url === "https://github.com/davepoon/buildwithclaude/tree/5864a032c1656350343fa982246ca9ffdd889c34/plugins/all-skills/skills/jev-social"));
assert.match(ecosystem, /pins the v0\.1\.10 runtime/i);
- assert.ok(ecosystem.includes(
- "https://github.com/kerpopule/hermes-jev-skills/blob/650090df0737d42806c90f6cecfea731ef753abb/skills/jev-social-research/SKILL.md",
- ));
+ assert.ok(ecosystemTargets.some((url) => url === "https://github.com/kerpopule/hermes-jev-skills/blob/650090df0737d42806c90f6cecfea731ef753abb/skills/jev-social-research/SKILL.md"));
assert.match(ecosystem, /separate bounded social-research workflow/i);
assert.match(ecosystem, /not the Jev Social runtime/i);
- assert.ok(ecosystem.includes(
- "https://github.com/sickn33/agentic-awesome-skills/blob/463b781eb48c8b3a48869090a2dbd56eeb41e7c3/skills/jev-social/SKILL.md",
- ));
+ assert.ok(ecosystemTargets.some((url) => url === "https://github.com/sickn33/agentic-awesome-skills/blob/463b781eb48c8b3a48869090a2dbd56eeb41e7c3/skills/jev-social/SKILL.md"));
assert.match(ecosystem, /marks the workflow `critical` risk/i);
assert.match(ecosystem, /explicit approval before the first remote package fetch/i);
assert.match(ecosystem, /not a security endorsement/i);
diff --git a/test/evidence-table-name.test.js b/test/evidence-table-name.test.js
index ee36f2b..8a5ad21 100644
--- a/test/evidence-table-name.test.js
+++ b/test/evidence-table-name.test.js
@@ -2,6 +2,8 @@ import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
+import { stripMarkup } from "../test-support/text.js";
+
const indexHtml = await readFile(
new URL("../public/index.html", import.meta.url),
"utf8",
@@ -19,10 +21,6 @@ function elementById(html, id) {
return match ? match[2] : null;
}
-function stripTags(text) {
- return text.replace(/<[^>]*>/g, "").trim();
-}
-
test("the evidence table has a non-empty accessible name built from the existing heading", () => {
const sectionMatch = indexHtml.match(
/<section\b[^>]*\bid="evidence-table"[^>]*>([\s\S]*?)<\/section>/i,
@@ -47,7 +45,7 @@ test("the evidence table has a non-empty accessible name built from the existing
.map((id) => {
const content = elementById(indexHtml, id);
assert.ok(content !== null, `expected an element with id="${id}" referenced by aria-labelledby`);
- return stripTags(content);
+ return stripMarkup(content).trim();
})
.join(" ")
.trim();
@@ -77,4 +75,4 @@ test("the evidence table accessible-name fix does not change visible copy or dyn
/<tbody\b[^>]*\bid="table-body"[^>]*><\/tbody>/i,
"#table-body must remain intact for dynamic rendering",
);
-});
\ No newline at end of file
+});
diff --git a/test/query-label.test.js b/test/query-label.test.js
index f55ad19..18402d8 100644
--- a/test/query-label.test.js
+++ b/test/query-label.test.js
@@ -2,6 +2,8 @@ import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
+import { stripMarkup } from "../test-support/text.js";
+
const indexHtml = await readFile(
new URL("../public/index.html", import.meta.url),
"utf8",
@@ -33,7 +35,7 @@ test("textarea#query has an explicit associated label with non-empty text", () =
const labelText = labelFor(indexHtml, "query");
assert.ok(labelText !== null, 'expected a <label for="query"> element');
assert.notEqual(
- labelText.replace(/<[^>]*>/g, "").trim(),
+ stripMarkup(labelText).trim(),
"",
"the label for textarea#query must contain non-empty text",
);
diff --git a/test/report.test.js b/test/report.test.js
index 4843cea..5fdc82f 100644
--- a/test/report.test.js
+++ b/test/report.test.js
@@ -52,6 +52,17 @@ test("grounded fallback reports separate claims, comments, metrics, inference, l
assert.deepEqual(validateResearchReport(report, input.items), { ok: true, errors: [] });
});
+test("comparison tables escape pipes and backslashes exactly once", () => {
+ const report = buildGroundedResearchReport({
+ ...input,
+ items: [{ ...input.items[0], caption: String.raw`Path \ note | evidence` }],
+ });
+
+ assert.ok(report.includes(String.raw`Path \\ note \| evidence`));
+ assert.doesNotMatch(report, /Path \\\\\\ note/);
+ assert.deepEqual(validateResearchReport(report, [input.items[0]]), { ok: true, errors: [] });
+});
+
test("empty and partial evidence produce an honest report without fabricated trends", async () => {
let called = false;
const result = await synthesizeResearchReport({