当我将 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 成员资格框架不是为高安全性系统设计的,在高安全性系统中,针对堆检查强化代码是一项业务需求。
因此,您只有两个选择:
使用不同的(自定义的)用户验证方法或
接受密码将在堆上保留一段时间的事实。
关于c# - 在 Membership.ValidateUser(string userName, string password) 中使用 SecureString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74012603/