@stacksjs/payments 0.75.593 → 0.75.597

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Stacks Path
2
2
 
3
+ Stripe Checkout returns default to `config.app.url`. Deployments with a separate
4
+ browser frontend can explicitly list its bare origin in
5
+ `config.payment.checkoutReturnOrigins`, for example `['https://app.example.com']`.
6
+ Only exact HTTP origins are accepted. Paths, credentials and wildcards are refused;
7
+ checkout callers cannot supply additional trusted origins.
8
+
3
9
  Easily work with file paths.
4
10
 
5
11
  ## ☘️ Features
@@ -1,7 +1,7 @@
1
1
  import type { UserModel } from '@stacksjs/orm';
2
2
  import type Stripe from 'stripe';
3
3
  /**
4
- * Validate that a redirect target URL is on the configured app origin.
4
+ * Validate a redirect target against the app origin and explicitly configured browser origins.
5
5
  * Without this, an attacker who could influence params (e.g. via a
6
6
  * forged form) could route the post-payment redirect to a phishing
7
7
  * site impersonating the brand. We compare origins (scheme+host+port)
@@ -1 +1 @@
1
- import{config}from"@stacksjs/config";import{stripe}from"../drivers/stripe";import{freshIdempotencyKey}from"../idempotency";export function assertSameOriginUrl(url,label){if(!url)return;let parsed;try{parsed=new URL(url)}catch{throw new Error(`[payments/checkout] ${label} is not a valid URL: ${url}`)}const appUrl=config?.app?.url;if(!appUrl)return;let appOrigin;try{appOrigin=new URL(appUrl.startsWith("http")?appUrl:`https://${appUrl}`).origin}catch{return}if(parsed.origin!==appOrigin){throw new Error(`[payments/checkout] ${label} origin (${parsed.origin}) does not match app origin (${appOrigin})`)}}export const manageCheckout=(()=>{async function create(user,params){const customerId=params.customer||user.stripe_id;if(!customerId){throw new Error("User has no Stripe customer")}assertSameOriginUrl(params.success_url,"success_url");assertSameOriginUrl(params.cancel_url,"cancel_url");const defaultParams={customer:customerId,mode:"payment",success_url:params.success_url,cancel_url:params.cancel_url};const mergedParams={...defaultParams,...params};return await stripe.checkout.sessions.create(mergedParams,{idempotencyKey:freshIdempotencyKey("checkout.session.create",user.id)})}return{create}})();
1
+ import{config}from"@stacksjs/config";import{stripe}from"../drivers/stripe";import{freshIdempotencyKey}from"../idempotency";export function assertSameOriginUrl(url,label){if(!url)return;let parsed;try{parsed=new URL(url)}catch{throw new Error(`[payments/checkout] ${label} is not a valid URL: ${url}`)}if(!["http:","https:"].includes(parsed.protocol)||parsed.username||parsed.password)throw new Error(`[payments/checkout] ${label} must be an HTTP URL without credentials`);const appUrl=config?.app?.url;if(!appUrl)return;let appOrigin;try{appOrigin=new URL(appUrl.startsWith("http")?appUrl:`https://${appUrl}`).origin}catch{return}const browserOrigins=config.payment?.checkoutReturnOrigins??[];const allowedOrigins=browserOrigins.map((value)=>{try{const origin=new URL(value);if(!["http:","https:"].includes(origin.protocol)||origin.username||origin.password||origin.pathname!=="/"||origin.search||origin.hash)throw new Error("Not a bare origin");return origin.origin}catch{throw new Error("[payments/checkout] checkoutReturnOrigins must contain bare HTTP origins without credentials")}});if(parsed.origin!==appOrigin&&!allowedOrigins.includes(parsed.origin)){throw new Error(`[payments/checkout] ${label} origin (${parsed.origin}) does not match app origin (${appOrigin})`)}}export const manageCheckout=(()=>{async function create(user,params){const customerId=params.customer||user.stripe_id;if(!customerId){throw new Error("User has no Stripe customer")}assertSameOriginUrl(params.success_url,"success_url");assertSameOriginUrl(params.cancel_url,"cancel_url");const defaultParams={customer:customerId,mode:"payment",success_url:params.success_url,cancel_url:params.cancel_url};const mergedParams={...defaultParams,...params};return await stripe.checkout.sessions.create(mergedParams,{idempotencyKey:freshIdempotencyKey("checkout.session.create",user.id)})}return{create}})();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/payments",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.593",
5
+ "version": "0.75.597",
6
6
  "description": "The Stacks payments package. Currently supporting Stripe.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -60,12 +60,12 @@
60
60
  "prepublishOnly": "bun run build"
61
61
  },
62
62
  "dependencies": {
63
- "@stacksjs/config": "0.75.593",
64
- "@stacksjs/database": "0.75.593",
65
- "@stacksjs/error-handling": "0.75.593",
66
- "@stacksjs/logging": "0.75.593",
67
- "@stacksjs/orm": "0.75.593",
68
- "@stacksjs/types": "0.75.593",
63
+ "@stacksjs/config": "0.75.597",
64
+ "@stacksjs/database": "0.75.597",
65
+ "@stacksjs/error-handling": "0.75.597",
66
+ "@stacksjs/logging": "0.75.597",
67
+ "@stacksjs/orm": "0.75.597",
68
+ "@stacksjs/types": "0.75.597",
69
69
  "stripe": "23.0.0"
70
70
  },
71
71
  "peerDependencies": {
@@ -77,7 +77,7 @@
77
77
  }
78
78
  },
79
79
  "devDependencies": {
80
- "@stacksjs/utils": "0.75.593",
80
+ "@stacksjs/utils": "0.75.597",
81
81
  "@stripe/stripe-js": "^10.0.0",
82
82
  "better-dx": "^0.2.39"
83
83
  }