Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Web/Resgrid.Web.Services/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public void ConfigureServices(IServiceCollection services)
{
options.AuthToken = NumberProviderConfig.TwilioAuthToken;
options.AllowLocal = false;
// BaseUrlOverride ensures the URL used for signature validation matches
// what Twilio used when signing the request, regardless of any scheme
// override applied by upstream middleware (e.g. http → https rewrites).
if (!string.IsNullOrWhiteSpace(Config.SystemBehaviorConfig.ResgridApiBaseUrl))
options.BaseUrlOverride = Config.SystemBehaviorConfig.ResgridApiBaseUrl;
Comment on lines +171 to +172
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find the default and any checked-in overrides. Expected: Twilio-enabled environments
# should provide a non-placeholder absolute http(s) ResgridApiBaseUrl.
rg -n -C2 'ResgridApiBaseUrl\s*='
rg -n -C2 'ResgridApiBaseUrl|RESGRID.*API.*BASE|Twilio(AuthToken|ApiUrl|Voice)' --iglob '*.json' --iglob '*.config' --iglob '*.cs'

Repository: Resgrid/Core

Length of output: 39189


Reject the placeholder Twilio base URL to prevent webhook validation failures.

The condition on line 171 is always true because SystemBehaviorConfig.ResgridApiBaseUrl defaults to https://resgridapi.local, a non-empty, non-whitespace string. When Twilio.AspNet.Core uses BaseUrlOverride for webhook signature validation, any environment with Twilio enabled but without an explicit public base URL will validate against https://resgridapi.local/api/Twilio/... instead of the actual public URL Twilio signed, causing all webhook requests to be rejected.

Replace the guard to explicitly validate that a real public URL is configured:

Proposed fix
-			if (!string.IsNullOrWhiteSpace(Config.SystemBehaviorConfig.ResgridApiBaseUrl))
-				options.BaseUrlOverride = Config.SystemBehaviorConfig.ResgridApiBaseUrl;
+			var baseUrlOverride = Config.SystemBehaviorConfig.ResgridApiBaseUrl?.Trim();
+			if (!string.IsNullOrWhiteSpace(NumberProviderConfig.TwilioAuthToken))
+			{
+				if (string.IsNullOrWhiteSpace(baseUrlOverride) ||
+					string.Equals(baseUrlOverride, "https://resgridapi.local", StringComparison.OrdinalIgnoreCase) ||
+					!Uri.TryParse(baseUrlOverride, UriKind.Absolute, out var baseUri) ||
+					(baseUri.Scheme != Uri.UriSchemeHttp && baseUri.Scheme != Uri.UriSchemeHttps))
+				{
+					throw new InvalidOperationException("SystemBehaviorConfig.ResgridApiBaseUrl must be set to the public Twilio webhook base URL when Twilio request validation is enabled.");
+				}
+
+				options.BaseUrlOverride = baseUrlOverride.TrimEnd('/');
+			}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Web/Resgrid.Web.Services/Startup.cs` around lines 171 - 172, The current
guard always sets options.BaseUrlOverride because
Config.SystemBehaviorConfig.ResgridApiBaseUrl defaults to the placeholder
"https://resgridapi.local"; change the condition so BaseUrlOverride is only set
when a real public URL is configured (e.g., non-empty AND not the placeholder).
Update the Startup.cs block that references
Config.SystemBehaviorConfig.ResgridApiBaseUrl and options.BaseUrlOverride to
check that ResgridApiBaseUrl is not null/whitespace and not equal to
"https://resgridapi.local" (and optionally not localhost/127.0.0.1 variants)
before assigning options.BaseUrlOverride.

});

services.AddApiVersioning(x =>
Expand Down
Loading