CVE-2024-43396: Khoj Cross-Site Scripting Vulnerability

MODERATE
Advisory Identifier: GHSA-cf72-vg59-4j4h
CVSS 5.4
CWE-79
Published
Advisory Summary

CVE-2024-43396 is a MODERATE (CVSS 5.4) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Khoj libraries in the PyPI ecosystem. The issue involves khoj vulnerable to stored cross-site scripting in automate (preview feature). Remediation is available by upgrading affected packages to version 1.15.0.

CVE-2024-43396 at a Glance

CVE Identifier CVE-2024-43396
GHSA Identifier GHSA-cf72-vg59-4j4h
Severity MODERATE
CVSS v3.1 Base Score 5.4
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Khoj
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 5.4

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability None (A:N)

How to Fix CVE-2024-43396

To remediate this vulnerability, upgrade all affected Khoj dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

khoj fixed: 1.15.0
pip install khoj>=1.15.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show khoj

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2024-43396, inspect your installed packages using pip:

pip show khoj

Analyze the terminal output to locate any version of Khoj in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.15.0), your application is affected.

Note: The pip show khoj command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Khoj, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary The Automation feature allows a user to insert arbitrary HTML inside the task instructions, resulting in a Stored XSS. ### Details The `q` parameter for the `/api/automation` endpoint does not get correctly sanitized when rendered on the page, resulting in the ability of users to inject arbitrary HTML/JS. ### PoC ``` POST /api/automation?q=%22%3E%3C%2Ftextarea%3E%3Cimg%20src%3Dx%20onerror%3Dalert(document.cookie)%3E%3Cscript%3Ealert(2)%3C%2Fscript%3E ``` ### Impact Stored XSS: ![image](https://github.com/khoj-ai/khoj/assets/115566010/6b5b9f60-e05c-448b-82b4-bf010ad8a4f0) ### Fix - Added a Content Security Policy to all config pages on the web client, including the automation page - Used DOM scripting to construct all components on the config pages, including the automation page

CVE-2024-43396 Affected Khoj Versions

1 component(s)
Fixed Versions:
1.15.0
Product / Package Ecosystem Affected Versions Fixed Version
khoj
PyPI
< 1.15.0
1.15.0

References

Frequently Asked Questions

What is CVE-2024-43396?
CVE-2024-43396 is a security vulnerability in Khoj involving Khoj Vulnerable to Stored Cross-site Scripting In Automate (Preview feature) under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Khoj versions are affected?
Affected versions include releases prior to 1.15.0 across affected packages: khoj.
What version fixes CVE-2024-43396?
Upgrading to 1.15.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is khoj affected?
Yes, khoj is affected in releases prior to 1.15.0. Upgrade your dependency to 1.15.0 or later.
What is the CVSS score of CVE-2024-43396?
CVE-2024-43396 has a CVSS v3.1 base score of 5.4 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N.
What CWE is associated with CVE-2024-43396?
CVE-2024-43396 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check PyPI dependencies for CVE-2024-43396?
Run the dependency tree command: 'pip show khoj'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-cf72-vg59-4j4h",
  "modified" : "2024-08-21T14:53:27Z",
  "published" : "2024-08-20T19:59:32Z",
  "aliases" : [ "CVE-2024-43396" ],
  "summary" : "Khoj Vulnerable to Stored Cross-site Scripting In Automate (Preview feature)",
  "details" : "### Summary\nThe Automation feature allows a user to insert arbitrary HTML inside the task instructions, resulting in a Stored XSS. \n\n### Details\nThe `q` parameter for the `/api/automation` endpoint does not get correctly sanitized when rendered on the page, resulting in the ability of users to inject arbitrary HTML/JS.\n\n### PoC\n```\nPOST /api/automation?q=%22%3E%3C%2Ftextarea%3E%3Cimg%20src%3Dx%20onerror%3Dalert(document.cookie)%3E%3Cscript%3Ealert(2)%3C%2Fscript%3E\n```\n\n### Impact\nStored XSS:\n![image](https://github.com/khoj-ai/khoj/assets/115566010/6b5b9f60-e05c-448b-82b4-bf010ad8a4f0)\n\n### Fix\n- Added a Content Security Policy to all config pages on the web client, including the automation page\n- Used DOM scripting to construct all components on the config pages, including the automation page",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "khoj"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.15.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/khoj-ai/khoj/security/advisories/GHSA-cf72-vg59-4j4h"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-43396"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/khoj-ai/khoj/commit/1c7a562880eeb7354325545d2cf6c5d1d1134812"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/khoj-ai/khoj/commit/55be90cdd2f9d6a09c8bf9ceea52fc36b9201626"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/khoj-ai/khoj"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-08-20T19:59:32Z",
    "nvd_published_at" : "2024-08-20T21:15:14Z"
  }
}