Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Validate header value in AddResponseFromClaims #25

Merged
merged 1 commit into from
May 27, 2021
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
7 changes: 6 additions & 1 deletion OCP.Msal.Proxy.Web/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,13 @@ internal static void AddResponseHeadersFromClaims(IEnumerable<Claim> claims, IHe
var claimName = claim.Type;
if (claimName.Contains("/")) claimName = claimName.Split('/')[claimName.Split('/').Length - 1];
var name = $"X-Injected-{claimName}";
if (!headers.ContainsKey(name)) headers.Add(name, claim.Value);
if (!headers.ContainsKey(name) && IsValidHeaderValue(claim.Value)) headers.Add(name, claim.Value);
}
}

internal static bool IsValidHeaderValue(string value)
{
return value.All(c => c >= 32 && c < 127);
}
}
}