Skip to content

Prompt Injection triggered XSS vulnerability in Khoj Obsidian, Desktop and Web clients

Moderate
debanjum published GHSA-h2q2-vch3-72qm Jul 8, 2024

Package

No package listed

Affected versions

<1.13.0

Patched versions

1.13.0

Description

Summary

The Khoj Obsidian, Desktop and Web clients inadequately sanitize the AI model's response and user inputs.
This can trigger Cross Site Scripting (XSS) via Prompt Injection from untrusted documents either indexed by the user on Khoj or read by Khoj from the internet when the user invokes the /online command

Affects

Users indexing a document with a malicious prompt or Khoj reading an adversarial website when a user uses the /online command in Khoj

Impact

  • Can notify an attacker of their malicious document being accessed by Khoj and/or the user
  • Can load unexpected, unwanted images into a users chat session
  • Can run undesired javascript on the users client app causing their machine to hang
  • Can steal secrets from the desktop app by using some preload.js exposed functions
  • Potential 1-Click RCE under system specific circumstances abusing HTML injection and special URI schemes.

Limitations

  • No cross-shard access possible
  • Does not affect references rendered in the reference section of the chat message. Requires the chat model to actually use the reference in its generated response text to trigger the XSS
  • Untrusted javascript can only run in a sandboxed iframe on the Obsidian client & with no access to the user's chat session

Details

The core issue is that Khoj's chat AI model can be made to follow adversarial crafted instructions in untrusted documents Khoj reads when trying to respond to a users query. This requires proper safety checks and locks on the Khoj chat interface to avoid any undesirable behavior caused by this temporary "take-over" of Khoj.

Example Scenario

  • User indexes a document with Khoj containing a malicious prompt/instruction
  • A chat message by the user triggers Khoj to read the malicious document and start following the malicious instruction in that document rather than the user's original instruction
  • This malicious instruction asks Khoj to inject the attacker provided HTML to load an external image, notifying the attacker of their malicious document having been accessed

Proof of Concept

To trigger it via user input:
Input: <img src=x onerror=alert(1)//> in your message to Khoj via the Obsidian chat modal -> results in triggering js in the chat UI.

To trigger it via AI response:
Input the above payload (the img one), and ask the AI to repeat what you just said

Fix

  • Sanitized rendered chat messages using DOMPurify
  • Added Content Security Policy (CSP) domain and content restrictions in the Obsidian, Desktop and Web chat clients

Future Improvements

  • Create and use finetuned chat LLM models to cleanly separate Data from Instructions. This should address prompt injection root-cause better

Severity

Moderate

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
High
Privileges required
None
User interaction
Required
Scope
Unchanged
Confidentiality
High
Integrity
None
Availability
Low

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:N/A:L

CVE ID

CVE-2024-25639

Weaknesses

Credits