Skip to content

Commit 0c0a715

Browse files
Copilotdata-douser
andauthored
[UPDATE PRIMITIVE] Fix markdown injection and platform-dependent path tests in prompt handlers (#162)
* Initial plan * Fix markdown injection and platform-dependent path tests in prompt handlers - Add sanitizeForInlineCode() helper to escape backticks and newlines in user-supplied values embedded in markdown code spans - Apply sanitizer to resolvePromptFilePath 'does not exist' warning (filePath and absolutePath) - Apply sanitizer to formatValidationError issue.received display - Fix POSIX path separator assumptions in tests: use basename only ('mydb', 'database') - Rename createSafePromptHandler tests to clarify they validate the handler wrapper, not MCP SDK validation Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/2660567b-5822-4505-91c2-37fe3ef00f4e * Replace sanitizeForInlineCode with CommonMark-compliant markdownInlineCode - markdownInlineCode() uses a fence length = maxRun+1 per CommonMark spec, preserving the original string (no information loss from backtick→apostrophe) - Normalises CR/CRLF to LF before wrapping (inline spans can't span lines) - Export markdownInlineCode for testability - Add 6 unit tests for markdownInlineCode (plain text, single/double backtick, CRLF normalisation, backtick-only values) - Add regression test for formatValidationError with backtick in received value - Add regression test for resolvePromptFilePath warning with backtick in path Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/ec7c534b-93ac-40e5-bcb6-023bc7496940 * Fix markdownInlineCode to replace newlines with spaces for single-line output Replace \r\n, \r, and \n with a space (not just normalize CRLF to LF) so the returned inline code span never contains a literal newline character. Update docstring and test to reflect space-replacement behavior. Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/87cfd54e-9d66-4871-a581-601aff3c6c8d --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
1 parent 0db4c6d commit 0c0a715

File tree

4 files changed

+124
-10
lines changed

4 files changed

+124
-10
lines changed

server/dist/codeql-development-mcp-server.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64468,6 +64468,23 @@ var SUPPORTED_LANGUAGES = [
6446864468
"ruby",
6446964469
"swift"
6447064470
];
64471+
function markdownInlineCode(value) {
64472+
const normalized = value.replace(/\r\n|\r|\n/g, " ");
64473+
let maxRun = 0;
64474+
let currentRun = 0;
64475+
for (const ch of normalized) {
64476+
if (ch === "`") {
64477+
currentRun += 1;
64478+
if (currentRun > maxRun) {
64479+
maxRun = currentRun;
64480+
}
64481+
} else {
64482+
currentRun = 0;
64483+
}
64484+
}
64485+
const fence = "`".repeat(maxRun + 1);
64486+
return `${fence}${normalized}${fence}`;
64487+
}
6447164488
async function resolvePromptFilePath(filePath, workspaceRoot) {
6447264489
if (!filePath || filePath.trim() === "") {
6447364490
return {
@@ -64503,7 +64520,7 @@ async function resolvePromptFilePath(filePath, workspaceRoot) {
6450364520
} catch {
6450464521
return {
6450564522
resolvedPath: absolutePath,
64506-
warning: `\u26A0 **File path** \`${filePath}\` **does not exist.** Resolved to: \`${absolutePath}\``
64523+
warning: `\u26A0 **File path** ${markdownInlineCode(filePath)} **does not exist.** Resolved to: ${markdownInlineCode(absolutePath)}`
6450764524
};
6450864525
}
6450964526
return { resolvedPath: absolutePath };
@@ -64599,7 +64616,7 @@ function formatValidationError(promptName, error2) {
6459964616
if (issue2.code === "invalid_enum_value" && "options" in issue2) {
6460064617
const opts = issue2.options.join(", ");
6460164618
lines.push(
64602-
`- **\`${field}\`**: received \`${String(issue2.received)}\` \u2014 must be one of: ${opts}`
64619+
`- **\`${field}\`**: received ${markdownInlineCode(String(issue2.received))} \u2014 must be one of: ${opts}`
6460364620
);
6460464621
} else if (issue2.code === "invalid_type") {
6460564622
lines.push(

0 commit comments

Comments
 (0)