Summary
PapersGPT for Zotero may execute attacker-controlled JavaScript when output from an LLM endpoint is passed unsanitized to window.eval(). If malicious content reaches that endpoint response through prompt injection, request interception, or a hostile custom service, code could run with Zotero's chrome-privileged access.
Affected context
The vulnerability occurs in PapersGPT for Zotero deployments that process LLM responses and evaluate returned content as JavaScript. Risk increases when PDFs or other inputs can influence prompts, API traffic can be intercepted or modified, or users can configure an untrusted custom LLM endpoint. Because the evaluation occurs in Zotero's privileged context, the resulting access may extend beyond ordinary web content restrictions.
Exploit preconditions
- Attack surface: LLM response handling within the PapersGPT Zotero extension
- Required access: Ability to influence the content returned by the configured LLM service, directly or indirectly
- Trigger point: Processing an LLM response that reaches the JavaScript evaluation path
- Why exploitation is possible: Response data is treated as executable JavaScript without sufficient sanitization, isolation, or trust validation
Why this happens
The underlying flaw is a code injection condition caused by evaluating externally influenced text through window.eval(). LLM output is data that may contain adversarial or manipulated content, but the application treats it as executable program logic. This behavior maps to CWE-94: Improper Control of Generation of Code, because an insufficiently controlled input-to-code boundary permits attacker-influenced JavaScript execution.
Potential impact
- Arbitrary JavaScript execution in the Zotero chrome-privileged context
- Reading, modifying, or deleting local files accessible to Zotero
- Process execution through available privileged application interfaces
- Exposure or manipulation of Zotero libraries, notes, attachments, and settings
- Possible persistence, data theft, or compromise of the user's workstation
General mitigation guidance
Mitigation generally focuses on eliminating dynamic evaluation of LLM output and reducing trust in model-generated content.
Common defensive patterns include:
- Treating all LLM responses as untrusted data rather than executable code
- Removing
eval()and equivalent dynamic code-generation paths - Using narrowly scoped, typed commands or structured data with strict schema validation when automation is required
- Isolating content processing from chrome-privileged APIs and applying least-privilege capability boundaries
- Authenticating and protecting LLM connections against interception or endpoint substitution
- Restricting custom endpoint configuration and clearly separating trusted instructions from document content
- Requiring explicit user approval for sensitive file, process, or data operations
How teams detect issues like this
Detection can combine static analysis, code review, and runtime policy controls:
- Search source code and dependencies for
eval(),Functionconstructors, dynamic script injection, and equivalent code-generation APIs - Review data flows from LLM responses, document text, network requests, and custom endpoint settings into executable sinks
- Flag privileged extension code that evaluates remotely influenced strings or exposes broad filesystem and process capabilities
- Enforce repository policies that prohibit dynamic evaluation of network- or model-derived content
- Add tests that verify adversarial or malformed LLM output remains inert and is handled only as structured data
- Use automated security review tools to identify untrusted-input-to-code-execution paths

