Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(billing): address review feedback
Tre Dubravad91389819d09
diff --git a/backend/src/ee/routes/v1/license-v2-router.ts b/backend/src/ee/routes/v1/license-v2-router.tsindex b6d329a23b..f421bbf71d 100644--- a/backend/src/ee/routes/v1/license-v2-router.ts+++ b/backend/src/ee/routes/v1/license-v2-router.ts@@ -6,8 +6,14 @@ import { readLimit, writeLimit } from "@app/server/config/rateLimiter";import { verifyAuth } from "@app/server/plugins/auth/verify-auth";import { AuthMode } from "@app/services/auth/auth-type";-// The license server joins this onto its configured portal origin, so it must be a relative path.-const ReturnPathSchema = z.string().trim().startsWith("/").optional();+// The license server joins this onto its configured portal origin, so it must be a single-rooted+// relative path. Reject protocol-relative ("//host") values that would escape the origin.+const ReturnPathSchema = z+ .string()+ .trim()+ .startsWith("/")+ .refine((path) => !path.startsWith("//"), { message: "must be a relative path" })+ .optional();const BillingV2DimSchema = z.object({key: z.string(),diff --git a/backend/src/ee/services/license-v2/license-v2-service.ts b/backend/src/ee/services/license-v2/license-v2-service.tsindex 435739dbf1..d1f5ed6312 100644--- a/backend/src/ee/services/license-v2/license-v2-service.ts+++ b/backend/src/ee/services/license-v2/license-v2-service.ts@@ -337,11 +337,22 @@ export const licenseV2ServiceFactory = ({const members = await orgDAL.countAllOrgMembers(orgId);+ // Name the plan from the subscription's tier so enterprise/trial orgs aren't all labelled "Pro".+ let planName = "Free";+ if (subState !== "no-subscription") {+ const tier = subscription?.items[0]?.plan;+ if (tier) {+ planName = tier.charAt(0).toUpperCase() + tier.slice(1);+ } else {+ planName = "Pro";+ }+ }+const overview: BillingV2Overview = {isCloud: true,mode: "self-serve",subState,- planName: subState === "no-subscription" ? "Free" : "Pro",+ planName,nextBillingDate,recurringAmount,interval,diff --git a/backend/src/services/license-client/license-client-backends.ts b/backend/src/services/license-client/license-client-backends.tsindex dc3535f802..08b2e7ee4f 100644--- a/backend/src/services/license-client/license-client-backends.ts+++ b/backend/src/services/license-client/license-client-backends.ts@@ -67,9 +67,9 @@ export const licenseServerBackend = (serverUrl: string, auth: TLicenseServerAuthreturn catalogResponseSchema.parse(body);},- // A brand-new org has no subscription; the server answers with a 404/500 or an empty status.- // Any non-200 or empty payload is treated as "no subscription" so a new customer renders the- // no-subscription state instead of an error.+ // A brand-new org has no license yet (404) or a license with no active subscription (200 with+ // status "none"); both are "no subscription". Other non-2xx statuses (auth failure, 5xx) are real+ // errors and must surface so a paying org isn't shown the free state during an outage.fetchSubscription: async (orgId: string): Promise<TSubscriptionResponse | null> => {const url = new URL(SUBSCRIPTION_PATH, serverUrl);url.searchParams.set("org_id", orgId);@@ -78,9 +78,12 @@ export const licenseServerBackend = (serverUrl: string, auth: TLicenseServerAuthheaders: { Authorization: `Bearer ${mintServiceToken(auth)}` },redirect: "manual"});- if (!res.ok) {+ if (res.status === 404) {return null;}+ if (!res.ok) {+ throw new Error(`license server responded with ${res.status}`);+ }const body: unknown = await res.json();const parsed = subscriptionResponseSchema.safeParse(body);diff --git a/backend/src/services/license-client/license-client-types.ts b/backend/src/services/license-client/license-client-types.tsindex 1410ad9780..5ffc65317b 100644--- a/backend/src/services/license-client/license-client-types.ts+++ b/backend/src/services/license-client/license-client-types.ts@@ -103,7 +103,7 @@ export const subscriptionResponseSchema = zexport const sessionResponseSchema = z.object({- url: z.string()+ url: z.string().url()}).passthrough();diff --git a/backend/src/services/license-client/license-client.ts b/backend/src/services/license-client/license-client.tsindex f7d1fa4c98..476c8b1651 100644--- a/backend/src/services/license-client/license-client.ts+++ b/backend/src/services/license-client/license-client.ts@@ -39,6 +39,19 @@ const buildBackend = (envConfig: TLicenseClientFactoryDep["envConfig"]): TLicensreturn null;}+ // Guard against a misconfigured base URL pointing the authenticated client at a non-http target.+ let parsedUrl: URL;+ try {+ parsedUrl = new URL(serverUrl);+ } catch {+ logger.warn("license-client: LICENSE_SERVER_V2_URL is not a valid URL; serving feature fallbacks");+ return null;+ }+ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {+ logger.warn("license-client: LICENSE_SERVER_V2_URL must use http(s); serving feature fallbacks");+ return null;+ }+return licenseServerBackend(serverUrl, { hmacSecret, issuer, audience });};diff --git a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsxindex 5dfcdbcdb8..abdf6d3060 100644--- a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx+++ b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx@@ -10,6 +10,7 @@ import {OrgPermissionBillingActions,OrgPermissionSubjects,useOrganization,+ useOrgPermission,useUser} from "@app/context";import {@@ -39,8 +40,13 @@ export const BillingV2Page = () => {const { t } = useTranslation();const { currentOrg } = useOrganization();const { user } = useUser();+ const { permission } = useOrgPermission();const orgId = currentOrg?.id ?? "";const billingEmail = user?.email ?? user?.username;+ const canManageBilling = permission.can(+ OrgPermissionBillingActions.ManageBilling,+ OrgPermissionSubjects.Billing+ );const { data: overview, isPending, isError, refetch } = useGetBillingV2Overview(orgId);const { data: catalog = [] } = useGetBillingV2Catalog(orgId);@@ -195,6 +201,7 @@ export const BillingV2Page = () => {onContact={onContact}onGetStarted={onGetStarted}onRetry={onRetry}+ canManageBilling={canManageBilling}getStartedLoading={createCheckoutSession.isPending}/></div>diff --git a/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx b/frontend/src/pages/organization/BillingV2Page/components/Overview.tsxindex 4f393067b2..b296d63633 100644--- a/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx+++ b/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx@@ -33,12 +33,19 @@ export type BillingV2RenderState =type BannerProps = {mode: BillingV2Mode;subState: BillingV2RenderState;+ canManage: boolean;onUpdatePayment: () => void;onManageSubscription: () => void;};// Banners (managed info / dunning).-const Banner = ({ mode, subState, onUpdatePayment, onManageSubscription }: BannerProps) => {+const Banner = ({+ mode,+ subState,+ canManage,+ onUpdatePayment,+ onManageSubscription+}: BannerProps) => {if (mode === "managed") {return (<div className="banner banner-info">@@ -63,15 +70,17 @@ const Banner = ({ mode, subState, onUpdatePayment, onManageSubscription }: BanneUpdate your payment method to avoid losing access. Your products are still active whilewe retry.</div>- <div className="b-actions">- <Button variant="warning" size="sm" onClick={onUpdatePayment}>- <IconCreditCard size={14} />- Update payment method- </Button>- <Button variant="outline" size="sm" onClick={onManageSubscription}>- Manage subscription- </Button>- </div>+ {canManage && (+ <div className="b-actions">+ <Button variant="warning" size="sm" onClick={onUpdatePayment}>+ <IconCreditCard size={14} />+ Update payment method+ </Button>+ <Button variant="outline" size="sm" onClick={onManageSubscription}>+ Manage subscription+ </Button>+ </div>+ )}</div></div>);@@ -86,15 +95,17 @@ const Banner = ({ mode, subState, onUpdatePayment, onManageSubscription }: BanneA payment kept failing and access is paused. Complete payment to restore access to yourproducts.</div>- <div className="b-actions">- <Button variant="danger" size="sm" onClick={onUpdatePayment}>- <IconCreditCard size={14} />- Update payment method- </Button>- <Button variant="outline" size="sm" onClick={onManageSubscription}>- Manage subscription- </Button>- </div>+ {canManage && (+ <div className="b-actions">+ <Button variant="danger" size="sm" onClick={onUpdatePayment}>+ <IconCreditCard size={14} />+ Update payment method+ </Button>+ <Button variant="outline" size="sm" onClick={onManageSubscription}>+ Manage subscription+ </Button>+ </div>+ )}</div></div>);@@ -154,10 +165,11 @@ const ErrorPanel = ({ onRetry }: ErrorPanelProps) => (type GetStartedProps = {onGetStarted: () => void;+ canManage: boolean;loading?: boolean;};-const GetStarted = ({ onGetStarted, loading }: GetStartedProps) => (+const GetStarted = ({ onGetStarted, canManage, loading }: GetStartedProps) => (<Card><div className="getstarted"><div className="gs-ico">@@ -167,10 +179,12 @@ const GetStarted = ({ onGetStarted, loading }: GetStartedProps) => (<div className="gs-text">Pick the products your team needs and check out securely. You can change or cancel any time.</div>- <Button variant="org" size="lg" onClick={onGetStarted} loading={loading}>- Get started- <IconArrowRight size={15} />- </Button>+ {canManage && (+ <Button variant="org" size="lg" onClick={onGetStarted} loading={loading}>+ Get started+ <IconArrowRight size={15} />+ </Button>+ )}</div></Card>);@@ -365,16 +379,19 @@ const ProductsCard = ({ overview, catalog, readOnly, onManage, onContact }: Prodtype PaymentCardProps = {overview: BillingV2Overview;+ canManage: boolean;onUpdate: () => void;};-const PaymentCard = ({ overview, onUpdate }: PaymentCardProps) => (+const PaymentCard = ({ overview, canManage, onUpdate }: PaymentCardProps) => (<Cardtitle="Payment method"action={- <Button variant="outline" size="sm" onClick={onUpdate}>- Update- </Button>+ canManage ? (+ <Button variant="outline" size="sm" onClick={onUpdate}>+ Update+ </Button>+ ) : undefined}>{overview.payment ? (@@ -400,16 +417,19 @@ const PaymentCard = ({ overview, onUpdate }: PaymentCardProps) => (type DetailsCardProps = {overview: BillingV2Overview;+ canManage: boolean;onEdit: () => void;};-const DetailsCard = ({ overview, onEdit }: DetailsCardProps) => (+const DetailsCard = ({ overview, canManage, onEdit }: DetailsCardProps) => (<Cardtitle="Billing details"action={- <Button variant="outline" size="sm" onClick={onEdit}>- Edit- </Button>+ canManage ? (+ <Button variant="outline" size="sm" onClick={onEdit}>+ Edit+ </Button>+ ) : undefined}>{overview.billingDetails ? (@@ -492,6 +512,7 @@ export type OverviewProps = {onContact: (prod: BillingV2CatalogProduct) => void;onGetStarted: () => void;onRetry: () => void;+ canManageBilling: boolean;getStartedLoading?: boolean;};@@ -506,6 +527,7 @@ export const Overview = ({onContact,onGetStarted,onRetry,+ canManageBilling,getStartedLoading}: OverviewProps) => {if (subState === "loading") {@@ -522,6 +544,8 @@ export const Overview = ({const { mode } = overview;const isManaged = mode === "managed";+ // Managed plans and read-only billing roles cannot mutate the subscription.+ const productsReadOnly = isManaged || !canManageBilling;if (subState === "no-subscription") {return (@@ -529,15 +553,20 @@ export const Overview = ({<Bannermode={mode}subState={subState}+ canManage={canManageBilling}onUpdatePayment={onUpdatePayment}onManageSubscription={onManageSubscription}/>- <GetStarted onGetStarted={onGetStarted} loading={getStartedLoading} />+ <GetStarted+ onGetStarted={onGetStarted}+ canManage={canManageBilling}+ loading={getStartedLoading}+ /><UsageCard overview={overview} /><ProductsCardoverview={overview}catalog={catalog}- readOnly={isManaged}+ readOnly={productsReadOnly}onManage={onUpgrade}onContact={onContact}/>@@ -552,6 +581,7 @@ export const Overview = ({<Bannermode={mode}subState={subState}+ canManage={canManageBilling}onUpdatePayment={onUpdatePayment}onManageSubscription={onManageSubscription}/>@@ -560,12 +590,16 @@ export const Overview = ({<ProductsCardoverview={overview}catalog={catalog}- readOnly={isManaged}+ readOnly={productsReadOnly}onManage={onUpgrade}onContact={onContact}/>- {showPayment && <PaymentCard overview={overview} onUpdate={onUpdatePayment} />}- {!isManaged && <DetailsCard overview={overview} onEdit={onEditDetails} />}+ {showPayment && (+ <PaymentCard overview={overview} canManage={canManageBilling} onUpdate={onUpdatePayment} />+ )}+ {!isManaged && (+ <DetailsCard overview={overview} canManage={canManageBilling} onEdit={onEditDetails} />+ )}{showPayment && <InvoicesCard invoices={overview.invoices} />}</div>);