double escape sequence inside a url : The request filtering module is configured to deny a request that contains a double escape sequence

后端 未结 5 631
攒了一身酷
攒了一身酷 2020-12-05 03:55

On my ASP.NET MVC application, I am trying to implement a URL like below :

/product/tags/for+families

When I try to run my appl

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 04:10

    So I ran into this when I was calling an API from an MVC app. Instead of opening the security hole, I modified my path.

    First off, I recommend NOT disabling this setting. It is more appropriate to modify the design of the application/resource (e.g. encode the path, pass the data in a header or in the body).

    Although this is an older post, I thought I would share how you could resolve this error if you are receiving this from a call to an API by using HttpUtility.UrlPathEncode method in System.Web.

    I use RestSharp for making calls out, so my example is using the RestRequest:

    var tags = new[] { "for", "family" };
    var apiRequest = new RestRequest($"product/tags/{HttpUtility.UrlPathEncode(string.Join("+", tags))}");
    

    This produces a path equal to:

    /product/tags/for%2Bfamilies

    On another note, do NOT build a dynamic query based on a user's inputs. You SHOULD always use a SqlParameter. Also, it is extremely important from a security perspective to return the values with the appropriate encoding to prevent injection attacks.

    ~Cheers

提交回复
热议问题