CVE-2024-52294: Khoj Khoj Has An IDOR Vulnerability

MODERATE
Advisory Identifier: GHSA-hq4h-w933-jm6c
CVSS 4.3
CWE-639
Published
Advisory Summary

CVE-2024-52294 is a MODERATE (CVSS 4.3) khoj has an idor vulnerability (CWE-639: Authorization Bypass Through User-Controlled Key) affecting Khoj libraries in the PyPI ecosystem. The issue involves khoj has an idor in subscription management allows unauthorized subscription modifications. Remediation is available by upgrading affected packages to version 1.29.0.

CVE-2024-52294 at a Glance

CVE Identifier CVE-2024-52294
GHSA Identifier GHSA-hq4h-w933-jm6c
Severity MODERATE
CVSS v3.1 Base Score 4.3
CWE Classification CWE-639: Authorization Bypass Through User-Controlled Key
Affected Product Khoj
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 4.3

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

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

How to Fix CVE-2024-52294

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.29.0
pip install khoj>=1.29.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-52294, 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.29.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-639: Authorization Bypass Through User-Controlled Key, where the system's authorization functionality does not prevent one user from gaining access to another user's data or record by modifying the key value identifying the data. 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 An Insecure Direct Object Reference (IDOR) vulnerability in the update_subscription endpoint allows any authenticated user to manipulate other users' Stripe subscriptions by simply modifying the email parameter in the request. ### Details The vulnerability exists in the subscription endpoint at `/api/subscription`. The endpoint uses an email parameter as a direct reference to user subscriptions without verifying object ownership. While authentication is required, there is no authorization check to verify if the authenticated user owns the referenced subscription. Vulnerable code in `/api/subscription`: ```python @subscription_router.patch("") @requires(["authenticated"]) async def update_subscription(request: Request, email: str, operation: str): # IDOR: email parameter directly references user subscriptions without ownership verification customers = stripe.Customer.list(email=email).auto_paging_iter() customer = next(customers, None) if operation == "cancel": # Any authenticated user can modify any subscription referenced by email customer_id = customer.id for subscription in stripe.Subscription.list(customer=customer_id): stripe.Subscription.modify(subscription.id, cancel_at_period_end=True) ``` ### PoC 1. Create a customer account in stripe: - Customer A: `adventure8812@zeropath.com` (attacker) 2. Log in as any user. 3. Send this request: ```http PATCH /api/subscription?email=adventure8812@zeropath.com&operation=cancel HTTP/1.1 ``` 4. The subscription for Customer A is successfully set to cancel. ### Impact High: Revenue loss via mass cancellation of subscriptions. Loss of customer trust by re-enabling subscriptions they had set to cancel. ### Resolution This was fixed in the following commit which limited subscription update operations to the authenticated user: https://github.com/khoj-ai/khoj/commit/47d3c8c23597900af708bdc60aced3ae5d2064c1. Support for arbitrarily presenting an email for update has been deprecated.

CVE-2024-52294 Affected Khoj Versions

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

References

Frequently Asked Questions

What is CVE-2024-52294?
CVE-2024-52294 is a security vulnerability in Khoj involving khoj has an IDOR in subscription management allows unauthorized subscription modifications under CWE-639: Authorization Bypass Through User-Controlled Key.
Which Khoj versions are affected?
Affected versions include releases prior to 1.29.0 across affected packages: khoj.
What version fixes CVE-2024-52294?
Upgrading to 1.29.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.29.0. Upgrade your dependency to 1.29.0 or later.
What is the CVSS score of CVE-2024-52294?
CVE-2024-52294 has a CVSS v3.1 base score of 4.3 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N.
What CWE is associated with CVE-2024-52294?
CVE-2024-52294 is classified under CWE-639: Authorization Bypass Through User-Controlled Key (The system's authorization functionality does not prevent one user from gaining access to another user's data or record by modifying the key value identifying the data.).
How can I check PyPI dependencies for CVE-2024-52294?
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-hq4h-w933-jm6c",
  "modified" : "2024-12-30T18:43:16Z",
  "published" : "2024-12-30T16:12:40Z",
  "aliases" : [ "CVE-2024-52294" ],
  "summary" : "khoj has an IDOR in subscription management allows unauthorized subscription modifications",
  "details" : "### Summary\nAn Insecure Direct Object Reference (IDOR) vulnerability in the update_subscription endpoint allows any authenticated user to manipulate other users' Stripe subscriptions by simply modifying the email parameter in the request.\n\n### Details\nThe vulnerability exists in the subscription endpoint at `/api/subscription`. The endpoint uses an email parameter as a direct reference to user subscriptions without verifying object ownership. While authentication is required, there is no authorization check to verify if the authenticated user owns the referenced subscription.\n\nVulnerable code in `/api/subscription`:\n```python\n@subscription_router.patch(\"\")\n@requires([\"authenticated\"])\nasync def update_subscription(request: Request, email: str, operation: str):\n    # IDOR: email parameter directly references user subscriptions without ownership verification\n    customers = stripe.Customer.list(email=email).auto_paging_iter()\n    customer = next(customers, None)\n    \n    if operation == \"cancel\":\n        # Any authenticated user can modify any subscription referenced by email\n        customer_id = customer.id\n        for subscription in stripe.Subscription.list(customer=customer_id):\n            stripe.Subscription.modify(subscription.id, cancel_at_period_end=True)\n```\n\n### PoC\n1. Create a customer account in stripe:\n   - Customer A: `adventure8812@zeropath.com` (attacker)\n\n2. Log in as any user.\n\n3. Send this request:\n```http\nPATCH /api/subscription?email=adventure8812@zeropath.com&operation=cancel HTTP/1.1\n```\n\n4. The subscription for Customer A is successfully set to cancel.\n\n### Impact\nHigh:\nRevenue loss via mass cancellation of subscriptions.\nLoss of customer trust by re-enabling subscriptions they had set to cancel.\n\n### Resolution\n\nThis was fixed in the following commit which limited subscription update operations to the authenticated user: https://github.com/khoj-ai/khoj/commit/47d3c8c23597900af708bdc60aced3ae5d2064c1. Support for arbitrarily presenting an email for update has been deprecated.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "khoj"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.29.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/khoj-ai/khoj/security/advisories/GHSA-hq4h-w933-jm6c"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-52294"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/khoj-ai/khoj/commit/47d3c8c23597900af708bdc60aced3ae5d2064c1"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/khoj-ai/khoj"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-639" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-12-30T16:12:40Z",
    "nvd_published_at" : "2024-12-30T17:15:09Z"
  }
}