c# - 在 Membership.ValidateUser(string userName, string password) 中使用 SecureString

标签 c# asp.net security asp.net-identity

当我将 SecureString 密码转换为字符串,然后通过 MembershipProvider 函数进行验证时,我在安全报告中发现了堆检查漏洞问题。我知道我应该使用 char[] 来处理密码而不是字符串。但是如何将 char[] 传递到内置函数中以避免出现此问题?

public static string SecureStringToString(SecureString ss)
{
   return Marshal.PtrToStringUni(Marshal.SecureStringToGlobalAllocUnicode(ss)); //<---Heap Inspection issue
}
...

Membership.ValidateUser(UserName, SecureStringToString(pwd));

最佳答案

But how can I pass [a SecureString] into the buil[t]-in function to avoid the issue?

你不能。 Membership.ValidateUser 没有接受 SecureString 的重载。为什么?我们不知道。也许 ASP.NET 成员资格框架不是为高安全性系统设计的,在高安全性系统中,针对堆检查强化代码是一项业务需求。

因此,您只有两个选择:

  1. 使用不同的(自定义的)用户验证方法或

  2. 接受密码将在堆上保留一段时间的事实。

关于c# - 在 Membership.ValidateUser(string userName, string password) 中使用 SecureString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74012603/

相关文章:

javascript - javascript 在 switch 中返回 false 后仍在发回

c# - 具有查询字符串参数的站点中的 SEO 关键字

java - 在android中解析JSON数组子属性

javascript - bcrypt.compare 是否容易受到定时攻击

node.js - 处理/防止潜在的恶意请求(AWS、Node.js)

c# - 在不破坏向后兼容性的情况下更改参数名称

c# - 如何根据点获取字符串的子代

java - 如何防止 Java 应用程序在内部运行自定义代码?

c# - 将 C# 代码列表导出为具有颜色语法的 HTML 代码

c# - 如何计算上传大文件的最佳 block 大小