Skip to content

khoj has an IDOR in subscription management allows unauthorized subscription modifications

Moderate severity GitHub Reviewed Published Dec 29, 2024 in khoj-ai/khoj • Updated Dec 30, 2024

Package

pip khoj (pip)

Affected versions

< 1.29.0

Patched versions

1.29.0

Description

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:

@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:

  2. Log in as any user.

  3. Send this request:

PATCH /api/[email protected]&operation=cancel HTTP/1.1
  1. 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: khoj-ai/khoj@47d3c8c. Support for arbitrarily presenting an email for update has been deprecated.

References

@sabaimran sabaimran published to khoj-ai/khoj Dec 29, 2024
Published to the GitHub Advisory Database Dec 30, 2024
Reviewed Dec 30, 2024
Published by the National Vulnerability Database Dec 30, 2024
Last updated Dec 30, 2024

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
Low
Privileges required
Low
User interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
Low
Availability
None

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:L/PR:L/UI:N/S:U/C:N/I:L/A:N

EPSS score

0.043%
(11th percentile)

Weaknesses

CVE ID

CVE-2024-52294

GHSA ID

GHSA-hq4h-w933-jm6c

Source code

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.