首页 > 解决方案 > API 滥用 - 安全漏洞问题 MVC APP

问题描述

Fortify 的工具报告了以下代码的“ API 滥用 - 批量分配:不安全的 Binder 配置” 我感谢有人帮助识别以下代码中的安全漏洞。下面的代码用于在全局上下文中创建应用程序会话,我们是否有其他最佳方法来实现与 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
}

谢谢你!!

标签: c#asp.net-mvcsecurityowaspsecure-coding

解决方案


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

我从代码中删除了下面的一组行,我在 sonarQube 报告中不再看到漏洞

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

推荐阅读