-
Notifications
You must be signed in to change notification settings - Fork 317
Fix Location header to respect X-Forwarded-Proto and X-Forwarded-Host headers #3095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -756,7 +756,7 @@ public static string FormatQueryString(NameValueCollection? queryStringParameter | |
| /// <param name="req">The HTTP request.</param> | ||
| /// <returns>The scheme string ("http" or "https").</returns> | ||
| /// <exception cref="DataApiBuilderException">Thrown when client explicitly sets an invalid scheme.</exception> | ||
| private static string ResolveRequestScheme(HttpRequest req) | ||
| internal static string ResolveRequestScheme(HttpRequest req) | ||
| { | ||
| string? rawScheme = req.Headers["X-Forwarded-Proto"].FirstOrDefault(); | ||
| string? normalized = rawScheme?.Trim().ToLowerInvariant(); | ||
|
|
@@ -780,7 +780,7 @@ private static string ResolveRequestScheme(HttpRequest req) | |
| /// <param name="req">The HTTP request.</param> | ||
| /// <returns>The host string.</returns> | ||
| /// <exception cref="DataApiBuilderException">Thrown when client explicitly sets an invalid host.</exception> | ||
| private static string ResolveRequestHost(HttpRequest req) | ||
| internal static string ResolveRequestHost(HttpRequest req) | ||
| { | ||
| string? rawHost = req.Headers["X-Forwarded-Host"].FirstOrDefault(); | ||
| string? trimmed = rawHost?.Trim(); | ||
|
|
@@ -803,7 +803,7 @@ private static string ResolveRequestHost(HttpRequest req) | |
| /// </summary> | ||
| /// <param name="scheme">Scheme, e.g., "http" or "https".</param> | ||
| /// <returns>True if valid, otherwise false.</returns> | ||
| private static bool IsValidScheme(string? scheme) | ||
| internal static bool IsValidScheme(string? scheme) | ||
| { | ||
| return scheme is "http" or "https"; | ||
| } | ||
|
|
@@ -813,7 +813,7 @@ private static bool IsValidScheme(string? scheme) | |
| /// </summary> | ||
| /// <param name="host">The host name (with optional port).</param> | ||
| /// <returns>True if valid, otherwise false.</returns> | ||
| private static bool IsValidHost(string? host) | ||
| internal static bool IsValidHost(string? host) | ||
| { | ||
|
Comment on lines
803
to
817
|
||
| if (string.IsNullOrWhiteSpace(host)) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -381,9 +381,12 @@ HttpContext httpContext | |
| // The third part is the computed primary key route. | ||
| if (operationType is EntityActionOperation.Insert && !string.IsNullOrEmpty(primaryKeyRoute)) | ||
| { | ||
| // Use scheme/host from X-Forwarded-* headers if present, else fallback to request values | ||
| string scheme = SqlPaginationUtil.ResolveRequestScheme(httpContext.Request); | ||
| string host = SqlPaginationUtil.ResolveRequestHost(httpContext.Request); | ||
| locationHeaderURL = UriHelper.BuildAbsolute( | ||
| scheme: httpContext.Request.Scheme, | ||
| host: httpContext.Request.Host, | ||
| scheme: scheme, | ||
| host: new HostString(host), | ||
| pathBase: baseRoute, | ||
|
Comment on lines
+384
to
390
|
||
| path: httpContext.Request.Path); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add integration test coverage to verify POST to a stored procedure returns a Location header using X-Forwarded-Proto and X-Forwarded-Host when present (similar to existing pagination nextLink forwarded-header test). This change alters externally visible response headers and is currently untested.