fix(saml): validate SITE_URL before constructing SAML callback URL#5383
fix(saml): validate SITE_URL before constructing SAML callback URL#5383devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Conversation
When SITE_URL is not configured, the SAML AssertionConsumerServiceURL becomes 'undefined/api/v1/sso/saml2/<id>' which is not a valid URI. Azure AD/Entra ID rejects this with AADSTS7500511. Add explicit validation to throw a clear error message instead of silently producing an invalid URL. Co-Authored-By: arsh@infisical.com <arshsb1998@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Greptile OverviewGreptile SummaryThis PR hard-fails SAML option generation when Confidence Score: 4/5
Important Files Changed
|
| if (!appCfg.SITE_URL) { | ||
| throw new BadRequestError({ | ||
| message: | ||
| "SITE_URL environment variable is not configured. SAML SSO requires SITE_URL to be set to your Infisical instance URL." | ||
| }); |
There was a problem hiding this comment.
Missing URL format validation
The new guard only checks that SITE_URL is non-empty, but callbackUrl/audience still become invalid URIs if SITE_URL is set to a non-absolute value (e.g. example.com, localhost:8080, trailing whitespace) which will continue to trigger IdP errors. Consider validating it’s a proper absolute http(s) URL (e.g. via new URL(appCfg.SITE_URL) and protocol check) and throw the same clear error if parsing fails.
Co-Authored-By: arsh@infisical.com <arshsb1998@gmail.com>
|
Closing due to inactivity for more than 7 days. Configure here. |
Context
When
SITE_URLis not configured (it is optional in the env schema), the SAMLAssertionConsumerServiceURLis constructed as"undefined/api/v1/sso/saml2/<id>"via a JS template literal with an undefined value. This is not a valid URI, causing Azure AD / Entra ID to reject the SAML AuthnRequest with:This is particularly likely to happen with self-hosted omnibus installations where the config key is
PUBLIC_URLbut the backend readsSITE_URL.This PR adds explicit guards before constructing the SAML config:
SITE_URLis defined (not empty/undefined)SITE_URLis a proper absolutehttp(s)URL vianew URL()parsing and protocol checkThe
audiencefallback (|| "") is also removed since it's now redundant after the guards.Reported by a customer running v0.158.0 with an Entra ID SAML SSO + HAProxy/Nginx setup.
Updates since last revision
new URL()+ protocol check) in addition to the empty check, so malformed values likeexample.comorftp://hostare also caught with a clear error message. This addresses the Greptile review feedback.Steps to verify the change
SITE_URLenv var.SITE_URLmust be configured, rather than producing a cryptic IdP error.SITE_URLto a non-URL value (e.g.example.com) and verify the format validation error is returned.Type
Checklist
type(scope): short descriptionReview pointers
SITE_URLbeing undefined or malformed. If the customer's omnibus package does properly mapPUBLIC_URL→SITE_URL, then these guards won't trigger and the issue may lie elsewhere (e.g., URL encoding, proxy behavior). However, the guards are still correct defensive coding regardless.|| ""fromaudienceis safe — it is, because the!appCfg.SITE_URLguard above guarantees it's defined at that point.catchblock is intentional — bothnew URL()parse failures and the explicit protocol-check error should produce the same user-facing message.SITE_URLusages in this file (redirect URLs at lines ~300, 304) are in the POST callback handler, which only executes after a successful SAML round-trip — if the callback URL was valid enough for the IdP to respond,SITE_URLmust be set. So no additional guards are needed there.Link to Devin run: https://app.devin.ai/sessions/02bf2a7f3b9344f08974ca4100c617f9
Requested by: @0xArshdeep