feat(paykit): add trusted origin allowlist#184
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR adds optional ChangesTrusted Origins Configuration and Validation
Sequence DiagramsequenceDiagram
participant definePayKitMethod
participant normalizeMethodInput
participant resolveAbsoluteUrl
participant resolveOrigin
definePayKitMethod->>normalizeMethodInput: paykit.options
normalizeMethodInput->>resolveAbsoluteUrl: paykit options
resolveAbsoluteUrl->>resolveOrigin: request, headers, paykit
resolveOrigin->>resolveOrigin: validate against trustedOrigins
alt origin in trustedOrigins
resolveOrigin-->>resolveAbsoluteUrl: origin
else origin not trusted
resolveOrigin-->>definePayKitMethod: TRUSTED_ORIGIN_INVALID error
end
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
This adds a
trustedOriginsoption to PayKit so relativesuccessUrl,cancelUrl, andreturnUrlvalues can be resolved only from an explicit allowlist of trusted origins.That tightens the request boundary for embedded billing flows and avoids trusting arbitrary request hosts or forwarded headers when the app uses path-based return URLs.
Closes #74
How it works
trustedOrigins?: string[]is now available oncreatePayKit({...})/billing/success, it first derives the request origin as beforetrustedOriginsis configured, the resolved origin must match the allowlist or the request is rejected withTRUSTED_ORIGIN_INVALIDtrustedOriginsentries that include paths, queries, or hashesExample
With that in place, this stays valid:
But PayKit will only expand those relative URLs if the incoming request origin is in
trustedOrigins.Breaking change
No required breaking change.
This is fully opt-in. Existing apps keep the current behavior unless they set
trustedOrigins.Tests
node ./node_modules/vitest/vitest.mjs run --config vitest.unit.config.ts packages/paykit/src/api/__tests__/define-route.test.tsbun run typecheck --filter=paykitjsSummary by CodeRabbit
New Features
trustedOriginsconfiguration option to PayKitOptions, allowing you to specify an allowlist of accepted origins when resolving return URLs in your payment flows.Tests