【问题标题】:Getting warning in Security Hotspot in SonarQube make sure that controlled safely here在 SonarQube 的安全热点中收到警告,确保在此处安全控制
【发布时间】:2021-04-29 22:04:35
【问题描述】:
    ClaimsPrincipal principal = new ClaimsPrincipal(identity);
    

控制权限是安全敏感的。它过去曾导致以下漏洞:

 CVE-2018-12999
 CVE-2018-10285
 CVE-2017-7455

建议是这样的。 类 SecurityPrincipalDemo { class MyIdentity : IIdentity // 敏感的自定义 IIdentity 实现应该被审查 { // ... }

class MyPrincipal : IPrincipal // Sensitive, custom IPrincipal implementations should be reviewed
{
    // ...
}
[System.Security.Permissions.PrincipalPermission(SecurityAction.Demand, Role = "Administrators")] // Sensitive. The access restrictions enforced by this attribute should be reviewed.
static void CheckAdministrator()
{
    WindowsIdentity MyIdentity = WindowsIdentity.GetCurrent(); // Sensitive
    HttpContext.User = ...; // Sensitive: review all reference (set and get) to System.Web HttpContext.User
    AppDomain domain = AppDomain.CurrentDomain;
    domain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); // Sensitive
    MyIdentity identity = new MyIdentity(); // Sensitive
    MyPrincipal MyPrincipal = new MyPrincipal(MyIdentity); // Sensitive
    Thread.CurrentPrincipal = MyPrincipal; // Sensitive
    domain.SetThreadPrincipal(MyPrincipal); // Sensitive

    // All instantiation of PrincipalPermission should be reviewed.
    PrincipalPermission principalPerm = new PrincipalPermission(null, "Administrators"); // Sensitive
    principalPerm.Demand();

    SecurityTokenHandler handler = ...;
    // Sensitive: this creates an identity.
    ReadOnlyCollection<ClaimsIdentity> identities = handler.ValidateToken(…);
}

 // Sensitive: review how this function uses the identity and principal.
void modifyPrincipal(MyIdentity identity, MyPrincipal principal)
{
    // ...
}

}

【问题讨论】:

    标签: c# asp.net-mvc model-view-controller sonarqube hotspot


    【解决方案1】:

    没关系。我通过声明私有只读来解决这个问题

    【讨论】:

      猜你喜欢
      • 2020-12-29
      • 2020-11-08
      • 2022-01-17
      • 2022-01-14
      • 2021-08-25
      • 2020-12-05
      • 2020-10-18
      • 2013-07-17
      • 2021-06-23
      相关资源
      最近更新 更多