diff --git a/Controllers/CookieProxyController.cs b/Controllers/CookieProxyController.cs index 3779327..369c30e 100644 --- a/Controllers/CookieProxyController.cs +++ b/Controllers/CookieProxyController.cs @@ -14,17 +14,19 @@ public class CookieProxyController : Controller { // Check if we are on the correct domain if (Request.Host.Host != Vars.AuthProxySubdomain + "." + Vars.UpstreamPrimaryDomain) return StatusCode(StatusCodes.Status421MisdirectedRequest); - + if (!Request.Cookies.ContainsKey("authelia_session") || string.IsNullOrWhiteSpace(dstDomain) || !Vars.PermittedDomains.Contains(dstDomain) - || string.IsNullOrWhiteSpace(tgt)) { + || string.IsNullOrWhiteSpace(tgt) + || !new Uri(tgt).Host.EndsWith(dstDomain)) { return BadRequest("Bad request."); } - var targetUrl = - $"https://{Vars.AuthProxySubdomain}.{dstDomain}/api/cookieproxy_stage_two?dstDomain={HttpUtility.UrlEncode(dstDomain)}&tgt={HttpUtility.UrlEncode(tgt)}"; - return Content($"Redirecting to cookie proxy (stage two) on the destination domain...
if you are not redirected automatically
", "text/html"); + var targetUrl = $"https://{Vars.AuthProxySubdomain}.{dstDomain}/api/cookieproxy_stage_two?dstDomain={HttpUtility.UrlEncode(dstDomain)}&tgt={HttpUtility.UrlEncode(tgt)}"; + return + Content($"Redirecting to cookie proxy (stage two) on the destination domain...
if you are not redirected automatically
", + "text/html"); } [HttpPost] @@ -35,7 +37,11 @@ public class CookieProxyController : Controller { if (!Request.Host.Host.StartsWith(Vars.AuthProxySubdomain + ".") || !Vars.PermittedDomains.Any(p => Request.Host.Host.EndsWith("." + p))) return StatusCode(StatusCodes.Status421MisdirectedRequest); - if (string.IsNullOrWhiteSpace(dstDomain) || !Vars.PermittedDomains.Contains(dstDomain) || string.IsNullOrWhiteSpace(cookie) || string.IsNullOrWhiteSpace(tgt)) { + if (string.IsNullOrWhiteSpace(dstDomain) + || !Vars.PermittedDomains.Contains(dstDomain) + || string.IsNullOrWhiteSpace(cookie) + || string.IsNullOrWhiteSpace(tgt) + || !new Uri(tgt).Host.EndsWith(dstDomain)) { return BadRequest("Bad request."); } diff --git a/Controllers/RedirectController.cs b/Controllers/RedirectController.cs index e41e620..4a6652e 100644 --- a/Controllers/RedirectController.cs +++ b/Controllers/RedirectController.cs @@ -14,7 +14,7 @@ public class RedirectController : Controller { return StatusCode(StatusCodes.Status421MisdirectedRequest); } - if (string.IsNullOrWhiteSpace(dstDomain) || !Vars.PermittedDomains.Contains(dstDomain) || string.IsNullOrWhiteSpace(tgt)) { + if (string.IsNullOrWhiteSpace(dstDomain) || !Vars.PermittedDomains.Contains(dstDomain) || string.IsNullOrWhiteSpace(tgt) || !new Uri(tgt).Host.EndsWith(dstDomain)) { Response.StatusCode = StatusCodes.Status421MisdirectedRequest; return BadRequest("Bad request."); }