微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Page_load方法可能泄漏服务器端的条件值,从而使用户可以从另一个网站进行跟踪

如何解决Page_load方法可能泄漏服务器端的条件值,从而使用户可以从另一个网站进行跟踪

在Checkmarx扫描解决方案时,我遇到了“跨站点历史记录处理”问题。

我遇到的问题是: xyz \ abc.aspx.cs的第40行的Page_Load方法可能泄漏服务器端的条件值,从而使用户可以从另一个网站进行跟踪。这可能构成违反隐私的行为。 这是代码,我在网上遇到错误(*)

protected void Page_Load(object sender,EventArgs e)
    {
        try
        {
            lblErrorMsg.Text = "";
            lblErrorMsg.Visible = false;

            if (!IsPostBack)
            {
                //Code to get the content page name.
                string[] strPageInfo = HttpContext.Current.Request.ServerVariables.GetValues("PATH_INFO");
                string strPage = strPageInfo[0].Substring(strPageInfo[0].LastIndexOf('/') + 1,((strPageInfo[0].Length - strPageInfo[0].LastIndexOf("/")) - 1)).ToLower();

                msg.MessageText = "Verifying access";
                oLogger.LogInfo(msg,"Verifying access");

                //firstly,check whether the logged-in user is authorized to view the page
                ManageAuthorization.CheckAccess(strPage,out BoolAccess);

                if (BoolAccess)
                {
                    msg.MessageText = "Authorized to perform operations";
                    oLogger.LogInfo(msg,"Authorized to perform operations");
                }
                else
                {
                    ////display unauthorized screen
                    msg.MessageText = "Unauthorized to perform operations";
                    oLogger.LogWarning(msg,"Unauthorized to perform operations");
                    RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
                    var byteArray = new byte[4];
                    var randomInteger = BitConverter.ToUInt32(byteArray,0);
                    Response.Redirect(String.Format("../Default/Unauthorized.aspx?r={0}",randomInteger),true);
                }
            }
        }
        catch (Exception ex)
        {
            msg.MessageText = "Error while loading the page,Exception is:" + ex.Message;
            oLogger.LogMessage(LogCategory.Error,msg);
        }
    }

我没有得到正确的答案,如何解决此问题,请任何人帮忙。在此先感谢:)

解决方法

Checkmarx将其标记为漏洞,因为威胁代理可能会危害浏览器的SOP,并可能通过活动推断来泄漏用户信息。

要对此进行补救,您需要在重定向中添加一个随机值:

msg.MessageText = "Unauthorized to perform operations";
oLogger.LogWarning(msg,"Unauthorized to perform operations");

RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
var byteArray = new byte[4];
provider.GetBytes(byteArray);
var randomInteger = BitConverter.ToUInt32(byteArray,0);

Response.Redirect(String.Format("../Default/Unauthorized.aspx?r={0}",randomInteger),true);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。