Skip to content

security: sanitize web content to prevent prompt injection (#248)#342

Open
Shraman123 wants to merge 1 commit into
exa-labs:mainfrom
Shraman123:fix/output-sanitization-injection-prevention
Open

security: sanitize web content to prevent prompt injection (#248)#342
Shraman123 wants to merge 1 commit into
exa-labs:mainfrom
Shraman123:fix/output-sanitization-injection-prevention

Conversation

@Shraman123

Copy link
Copy Markdown

What this fixes

Issue #248 identified that text content returned from web pages
(title, text, summary, highlights, context) was not sanitized before
being passed to the AI context window.

A malicious webpage could embed strings like <tool_call> or
ignore previous instructions in its content and have them executed
by the AI as instructions.

Changes

  • Added sanitizeTextContent() with truncation + injection pattern removal
  • Applied to all user-controlled string fields: text, summary,
    title, highlights, context
  • Added MAX_TEXT_LENGTH (10,000 chars) and MAX_HIGHLIGHT_LENGTH
    (2,000 chars) to bound response size

Testing

Existing TypeScript build passes. The sanitizer is pure functions
with no external dependencies — easy to unit test.

Closes #248

- Add sanitizeTextContent() that truncates long strings and strips
  known prompt injection patterns (tool tags, INST markers, system
  prefixes, 'ignore previous instructions' etc.)
- Apply sanitization to user-controlled content fields: text, summary,
  title, and highlights in sanitizeSearchResult()
- Sanitize context field in sanitizeTopLevelResponse()
- Add MAX_TEXT_LENGTH (10k chars) and MAX_HIGHLIGHT_LENGTH (2k chars)
  caps to bound payload size

Closes exa-labs#248
@vercel

vercel Bot commented May 21, 2026

Copy link
Copy Markdown

@Shraman123 is attempting to deploy a commit to the Exa Team on Vercel.

A member of the Team first needs to authorize it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security audit findings — tool description injection + missing output sanitization

1 participant