Skip to content

fix: escape markdown characters in web search result titles and descriptions - #1282

Open
awhite0030 wants to merge 3 commits into
Nano-Collective:mainfrom
awhite0030:fix/web-search-markdown-escape-7015306932585013219
Open

awhite0030 wants to merge 3 commits into
Nano-Collective:mainfrom
awhite0030:fix/web-search-markdown-escape-7015306932585013219

Conversation

@awhite0030

Copy link
Copy Markdown
Contributor

Description

Brief description of what this PR does

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Docs-only or internal chores need no changeset (or run pnpm changeset --empty to note that intentionally).

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Checklist

  • If this was for an open issue, I was assigned to it
  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

Root cause: Search result titles and descriptions from the Brave Search API may contain characters that could be misinterpreted as Markdown syntax (e.g., *, _, [, ], <), leading to corrupted layout formatting or unintended link spoofing when compiled into the final markdown output.

Fix: Created an escapeMarkdown utility function that escapes common markdown characters. Applied this function to format the title and description of each Brave Search API result in web-search.tsx. Added comprehensive test coverage for the escaping logic. Included a valid changeset.

Validation:

corepack enable
pnpm install --frozen-lockfile
pnpm run build
pnpm test:format
pnpm test:lint
pnpm test:types
pnpm test:knip
pnpm test:ava

Fixes #1146

Fixes #1146

@github-actions github-actions Bot added the area:tools Tool implementations and tool-calling label Sep 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

nc-review: needs work — 1 blocking, 2 important, 1 nit

@awhite0030 — there is a blocking item below.

The fix itself is correct: the new escapeMarkdown utility escapes the relevant markdown meta-characters, the integration point in web-search.tsx correctly applies it to title and description, and tests cover both layers. However, the PR also rewrites every file in badges/ — including stars.svg, whose embedded target URL is now the contributor's personal fork (awhite0030/nanocoder) rather than the upstream Nano-Collective/nanocoder referenced from README.md. Those badge edits are unrelated to the security fix and the stars.svg change is actively harmful: it would re-point a README-linked badge at a fork. They need to be dropped before this can merge.

🔴 blocking · scope · badges/stars.svg:1

The PR rewrites badges/stars.svg and the embedded <a target="_blank" href="..."> links inside the SVG now point at the contributor's fork awhite0030/nanocoder instead of Nano-Collective/nanocoder. The README renders this badge directly:

![Stars](https://github.com/Nano-Collective/nanocoder/raw/main/badges/stars.svg)

So clicking the badge in the rendered README would navigate to the contributor's fork, not the project. This is unrelated to the markdown-escape fix. Drop the badge rewrite (revert all badges/*.svg changes) before merging.

🟠 important · scope · badges/coverage.svg

Five other files in badges/ (coverage.svg, forks.svg, npm-downloads-monthly.svg, repo-size.svg, and the build/npm-license ones the diff metadata lists) are also rewritten, even though they have nothing to do with the web-search markdown-escape fix. CONTRIBUTING and the project rubric both flag drive-by changes mixed into a functional PR as a problem (harder to review, harder to revert). Revert the whole badges/ directory in this PR.

🟠 important · changeset

The PR claims to include .changeset/web-search-markdown-escape.md, and the diff metadata confirms the file is added, but the changeset contents are not visible in the supplied diff snippet so I cannot verify the package name, bump level, or that the body follows the project's changelog voice. The package name must resolve to @nanocollective/nanocoder against the workspace (see project rubric). A maintainer should eyeball the changeset on the PR before merging.

⚪ nit · completeness · source/tools/web-search.tsx:84

formattedResults += \**URL:** ${result.url}\n\n`;result.url is not escaped. URLs containing backticks or ) could still break the markdown if you ever decide to wrap URLs in [label](url) form. For the current plain-rendering output it is fine, so this is a nit rather than a bug, but worth noting since the issue (#1146) is explicitly about preventing markdown injection from search-result fields.


🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional

Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with /re-review.

@github-actions github-actions Bot added the agent:needs-work nc-review found blocking findings label Sep 13, 2026
@will-lamerton

Copy link
Copy Markdown
Member

Can you take a look at the bot comments and merge conflicts please @awhite0030 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:needs-work nc-review found blocking findings area:tools Tool implementations and tool-calling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] web-search.tsx unsafe markdown emission

3 participants