API滥用-安全漏洞问题MVC APP

时间:2021-06-13 17:43:28

标签: c# asp.net-mvc security owasp secure-coding

Fortify 有工具报告了以下代码的“API 滥用 - 批量分配:不安全的绑定器配置”我感谢有人帮助识别以下代码中的安全漏洞。以下代码用于在全局上下文中创建应用程序会话,我们是否有其他最佳方法可以使用 OWASP 标准实现相同的会话

public class SessionKeys
{
    public const string AppHistory = "my_History ";       
}

public class AppSession : IAppSession
{
    public AppHistoryViewModel AppHistory 
    {
        get
        {
            AppHistoryViewModel appHistory  = null;

            if ((HttpContext.Current != null) && (HttpContext.Current.Session[SessionKeys.AppHistory] != null))
            {
                appHistory  = HttpContext.Current.Session[SessionKeys.AppHistory] as AppHistoryViewModel;
            }

            return appHistory;   
        }
        set
        {
            if (HttpContext.Current != null)
            {
                HttpContext.Current.Session[SessionKeys.AppHistory] = value;
            }
        }
    }
}

[UserProfileAuthorizationFilter(Order = 0)]
public class MyController : BaseController
{
    #region Setter Injection

    private IAppSession _appSession;

    public IAppSession AppSession
    {
        get { return _appSession ?? (_appSession = new AppSession()); }
        set
        {
            if (_appSession == null)
            {
                _appSession = value;
            }
        }
    }

    #endregion
}

谢谢!!

1 个答案:

答案 0 :(得分:0)

从 AppHistoryViewModel 中删除 setter 属性后,它起作用了。

我从代码中删除了以下几行,在 sonarQube 报告中看不到漏洞

 set
        {
            if (HttpContext.Current != null)
            {
                HttpContext.Current.Session[SessionKeys.AppHistory] = value;
            }
        }