Make allowed email domains configurable via AVAILABLE_DOMAINS env var - #1209
Make allowed email domains configurable via AVAILABLE_DOMAINS env var#1209louisremi wants to merge 2 commits into
Conversation
Allow operators to configure the email domains accepted for mock SAML login through a comma-separated AVAILABLE_DOMAINS env var, instead of the hardcoded example.com/example.org. Defaults to example.com,example.org when unset, so behavior is unchanged out of the box. - lib/env.ts: parse and expose availableDomains on config - pages/api/saml/auth.ts: validate against availableDomains; also return on the 403 so a SAML response is no longer generated for denied emails - pages/saml/login.tsx: pass domains via getServerSideProps and drive the dropdown options, default selection, and info text from the list - pages/namespace/[namespace]/saml/login.tsx: re-export getServerSideProps - .env.example: document the new variable Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@louisremi is attempting to deploy a commit to the ory Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a configurable ChangesConfigurable SAML domain allowlist
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 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)
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: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/env.ts`:
- Around line 9-12: The availableDomains variable in lib/env.ts can become an
empty array if AVAILABLE_DOMAINS is set to only whitespace or commas, causing
availableDomains[0] to be undefined downstream in pages/saml/login.tsx. After
the filter operation in the availableDomains assignment, add validation to
ensure the array is never empty by either providing a fallback to the default
domains (example.com,example.org) if the parsed array is empty, or throwing an
error to fail-fast on invalid configuration.
In `@pages/api/saml/auth.ts`:
- Around line 12-14: The email domain extraction using email.split('@')[1] lacks
proper validation, allowing potential security bypasses and crashes. Add
validation to ensure email is a string with exactly one @ symbol before
extracting the domain, then normalize the extracted domain to lowercase before
checking it against config.availableDomains to prevent case-sensitivity issues
and ensure safe authorization checks.
🪄 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 Plus
Run ID: 01d53149-5c0d-481a-b606-23b3e39b9b00
📒 Files selected for processing (5)
.env.examplelib/env.tspages/api/saml/auth.tspages/namespace/[namespace]/saml/login.tsxpages/saml/login.tsx
Address automated review feedback: - lib/env.ts: fall back to the default domains if AVAILABLE_DOMAINS parses to an empty list (e.g. ", ,"), so we never end up with an empty allowlist that blocks every login. - pages/api/saml/auth.ts: reject non-string emails and require exactly one "@" with a non-empty local part and domain before the allowlist check, so a malformed value like "a@example.com@evil.com" can't slip an allowed domain past the check (returns 400 instead of crashing or bypassing). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Cherry-picked from upstream PR ory#1209 (unmerged), rebased onto the PR ory#1200 attribute work: hardened email validation (single-@, non-empty parts), allowlist parsed from AVAILABLE_DOMAINS with a safe fallback, and the login form's domain picker driven by the configured list. Also fixes the upstream missing-return after the 403 (response double-send).
Cherry-picked from upstream PR ory#1209 (unmerged), rebased onto the PR ory#1200 attribute work: hardened email validation (single-@, non-empty parts), allowlist parsed from AVAILABLE_DOMAINS with a safe fallback, and the login form's domain picker driven by the configured list. Also fixes the upstream missing-return after the 403 (response double-send). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Summary
Makes the email domains accepted for the mock SAML login configurable via a new
AVAILABLE_DOMAINSenvironment variable (a comma-separated list), instead of the hardcodedexample.com/example.org.When the variable is unset, it defaults to
example.com,example.org, so existing behavior is unchanged out of the box.Motivation
When self-hosting Mock SAML for SSO testing, it's often useful to accept additional/organization-specific email domains without forking and editing the source. A single env var makes the running container configurable.
Changes
lib/env.ts— parseAVAILABLE_DOMAINS(trim entries, drop empties) and exposeavailableDomainson the sharedconfigobject.pages/api/saml/auth.ts— validate the email's domain againstconfig.availableDomains. This also adds a missingreturnon the 403 response — previously the request continued and a SAML response was still generated for a denied email.pages/saml/login.tsx— pass the domains to the client viagetServerSideProps(the var is intentionally notNEXT_PUBLIC_-prefixed, so it stays server-side). The domain dropdown options, the default selection, and the info-box text are now all derived from the configured list.pages/namespace/[namespace]/saml/login.tsx— re-exportgetServerSidePropsso the namespaced login route receives the prop too..env.example— document the new variable.Backward compatibility
Fully backward compatible — with
AVAILABLE_DOMAINSunset, the allowed domains remainexample.comandexample.org.🤖 Generated with Claude Code
Summary by CodeRabbit