fix: remove origin refine from checkout Zod schema to prevent Permiss…#159
fix: remove origin refine from checkout Zod schema to prevent Permiss…#159
Conversation
…ion denied graphql-shield catches errors thrown from rules and silently returns false, which hits fallbackError(false) = 'Permission denied' instead of the real validation error. The origin refine was causing this when FRONTEND_URL was not correctly configured in production. URL format validation stays in the schema (Shield layer). Origin enforcement stays in stripe.ts isSameOrigin() which silently falls back to the default URLs instead of throwing.
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe checkout schema's return URL validation was simplified by removing the custom origin-checking function ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@backend/src/validation/schemas/checkout.schema.ts`:
- Line 13: The schema currently allows any absolute URL via the returnUrl field
(returnUrl: z.string().url(...)) while stripe.ts silently drops non-frontend
origins; instead enforce origin checks and fail fast: update checkout.schema.ts
to either restrict returnUrl to the configured FRONTEND_URL origin (or remove
permissive .url and require a sentinel like { origin: FRONTEND_URL } if Shield
can't express it) or, if keeping structural validation, add an explicit
post-Shield validation in the checkout creation flow (the function that
builds/creates the Stripe session in backend/src/services/stripe.ts such as the
checkout session creation code) that compares new URL input to
process.env.FRONTEND_URL and throws a badInput/config error when mismatched so
callers get a clear rejection rather than a successful-but-ignored session;
ensure the error path is used before any fallback successUrl/cancelUrl are
generated.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5f21de59-be12-4856-97ca-9d9cb515cca6
📒 Files selected for processing (1)
backend/src/validation/schemas/checkout.schema.ts
…ring
When returnUrl is provided but its origin does not match config.frontendUrl,
throw StripeServiceError('INVALID_RETURN_URL') (mapped to BAD_USER_INPUT)
instead of silently falling back. This ensures callers get a clear 400
rejection with a meaningful message rather than an accepted-but-ignored
session. The check runs before any successUrl/cancelUrl construction.
…ion denied
graphql-shield catches errors thrown from rules and silently returns false, which hits fallbackError(false) = 'Permission denied' instead of the real validation error. The origin refine was causing this when FRONTEND_URL was not correctly configured in production.
URL format validation stays in the schema (Shield layer). Origin enforcement stays in stripe.ts isSameOrigin() which silently falls back to the default URLs instead of throwing.
Summary by CodeRabbit