Forum Discussion

abeckham7305's avatar
abeckham7305
Regular Visitor
1 year ago
Solved

Custom Security Extension using Forms Authentication sending invalid URI on redirect

I implemented a custom security extension for PowerBI server using the sample provided at https://github.com/microsoft/Reporting-Services/blob/master/CustomSecuritySample.  I updated the Logon Page_L...
  • abeckham7305's avatar
    1 year ago

    I figured out a solution.  It's more of a workaround though.

     

    I learned, without any specific details, that Windows Server 2022 datacenter has much more restrictive policies around URL validation and allowable query strings.  My custom extension only needs the query string in order to determine where to redirect the user back to PowerBI once they are authenticated.  Instead of trying to capture this in my Page_Load method, I moved that code to the OnInit method at the very beginning.  I first check for the ReturnUrl parameter and if present I capture the url parameter from it into a cookie and then immediately redirect to my Logon.aspx page again without any query string.

     

    Here's an example of the code:

    override protected void OnInit(EventArgs e)
    {
    var uri = new Uri(HttpContext.Current.Request.Url.AbsoluteUri);
    var returnUrl = HttpUtility.ParseQueryString(uri.Query).Get("ReturnUrl");
    if (returnUrl != null)
    {
    var returnUri = new Uri("https://dummy.com" + returnUrl);
    var encodedRedirectUrl = returnUri != null ? HttpUtility.ParseQueryString(returnUri.Query).Get("url") : null;
    var decodedRedirectUrl = encodedRedirectUrl != null ? HttpUtility.UrlDecode(encodedRedirectUrl) : null;
    if (decodedRedirectUrl != null)
    {
    var redirectUrlCookie = new HttpCookie("redirectUrl", decodedRedirectUrl)
    {
    HttpOnly = true,
    Secure = true
    };
    Response.Cookies.Add(redirectUrlCookie);
    }
    string urlWithoutQueryString = uri.GetLeftPart(UriPartial.Path);
    HttpContext.Current.Response.Redirect(urlWithoutQueryString);
    }

    InitializeComponent();
    base.OnInit(e);
    }

     

    This manages to remove the query string from the URL that PowerBI is providing before the Windows Server 2022 restrictions apply to it.

     

    Now my custom extension works on both Windows Server 2019 and 2022.