Skip to content

billing/pm-24665/license-file-generation-should-fail-for-unpaid-subscription#7444

Open
cyprain-okeke wants to merge 13 commits intomainfrom
billing/pm-24665/license-file-generation-should-fail-for-unpaid-subscription
Open

billing/pm-24665/license-file-generation-should-fail-for-unpaid-subscription#7444
cyprain-okeke wants to merge 13 commits intomainfrom
billing/pm-24665/license-file-generation-should-fail-for-unpaid-subscription

Conversation

@cyprain-okeke
Copy link
Copy Markdown
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-24665

📔 Objective

The PR adds validation to the license generation endpoint that blocks license file downloads when an organization's subscription is in any of these statuses:

  • canceled - Subscription has been canceled
  • incomplete - Payment setup incomplete
  • incomplete_expired - Payment setup expired before completion
  • unpaid - Payment failed and not resolved (bonus validation)

Technical Implementation

Location: src/Core/Billing/Organizations/Queries/GetCloudOrganizationLicenseQuery.cs

Changes:

  1. Added ValidateSubscriptionForLicenseGeneration() method that checks subscription status before allowing license generation
  2. Throws a BadRequestException with user-friendly error message: "Unable to generate license due to a payment issue. Please update your billing information or contact support for assistance."
  3. Validates at the API endpoint: GET /organizations/{id}/license

Test Coverage:

  • Added 8 comprehensive test cases covering all blocked statuses and ensuring valid statuses (active, trialing, past_due) still work

📸 Screenshots

image

@cyprain-okeke cyprain-okeke requested a review from a team as a code owner April 10, 2026 17:00
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 10, 2026

Logo
Checkmarx One – Scan Summary & Details9ca5736f-d9a0-412f-95c7-4716323a0e62


New Issues (4) Checkmarx found the following issues in this Pull Request
# Severity Issue Source File / Package Checkmarx Insight
1 HIGH Path_Traversal /src/Api/Controllers/SelfHosted/SelfHostedOrganizationLicensesController.cs: 56
detailsMethod at line 56 of /src/Api/Controllers/SelfHosted/SelfHostedOrganizationLicensesController.cs gets dynamic data from the model element. This ...
Attack Vector
2 MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1558
detailsMethod at line 1558 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter value flows ...
Attack Vector
3 MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 452
detailsMethod at line 452 of /src/Api/Auth/Controllers/AccountsController.cs gets a parameter from a user request from model. This parameter value flow...
Attack Vector
4 MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1385
detailsMethod at line 1385 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter value flows ...
Attack Vector

Fixed Issues (4) Great job! The following issues were fixed in this Pull Request
Severity Issue Source File / Package
MEDIUM CSRF /src/Api/KeyManagement/Controllers/AccountsKeyManagementController.cs: 145
MEDIUM CSRF /src/Api/KeyManagement/Controllers/AccountsKeyManagementController.cs: 97
MEDIUM CSRF /src/Api/KeyManagement/Controllers/AccountsKeyManagementController.cs: 173
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 287

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.77%. Comparing base (d9aef5c) to head (e61fd83).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7444      +/-   ##
==========================================
+ Coverage   58.75%   58.77%   +0.02%     
==========================================
  Files        2071     2071              
  Lines       91252    91270      +18     
  Branches     8130     8134       +4     
==========================================
+ Hits        53611    53646      +35     
+ Misses      35726    35721       -5     
+ Partials     1915     1903      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@amorask-bitwarden amorask-bitwarden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about premium?


public static class SubscriptionLicenseValidator
{
public static void ValidateSubscriptionForLicenseGeneration(SubscriptionInfo subscriptionInfo)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ I don't think there's any reason for this to take a SubscriptionInfo when we can just pass in Subscription.

{
public async Task<UserLicense> Run(User user)
{
var subscriptionInfo = await paymentService.GetSubscriptionAsync(user);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ This work should be done in the query itself and it should just use the StripeAdapter to get the subscription per the comment here: https://github.com/bitwarden/server/pull/7444/changes#r3081694476

}

var subscriptionInfo = await GetSubscriptionAsync(organization);
SubscriptionLicenseValidator.ValidateSubscriptionForLicenseGeneration(subscriptionInfo);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

@amorask-bitwarden amorask-bitwarden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this further, I'm not sure an entirely new validator is required for this work, which is evidenced by fact we're only checking the subscription status to make sure the subscription isn't terminal. Is there any reason we can't just check the subscription status in each license query? That way you don't have to double fetch the subscription in the org license query nor did you need an entirely new file.

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants