我的代码是这样的:
if (!confirmPassword) {
errors.confirmPassword = DefaultValidateErrors.confirmPassword;
} else if (password && password !== confirmPassword) {
errors.confirmPassword = DefaultValidateErrors.confirmPasswordMatch;
}tslint已经将其标记为tsr-detect-possible-timing-attacks,这听起来是正确的,但是我该如何修复它呢?
发布于 2018-10-12 21:12:10
我认为这是一个误报,您可以直接抑制lint警告。lint规则查找any variable named password,但计时攻击仅在涉及客户端未知的数据时才相关,例如,当根据保存的正确密码检查尝试登录的客户端指定的密码时。看起来这段代码只是在验证一个经过身份验证的用户设置的新密码。
也就是说,为了避免相关的计时攻击,一个web search found me the rule documentation链接到a post,并提供了一个建议的解决方案,使用逐位操作在固定时间内比较两个密码。(您可能认为该功能应该在某个库中。也许就是这样。)
发布于 2019-11-06 21:58:53
如果您在node中且版本为v6.6.0+,则可以使用crypto模块的timingSafeEqual。
const crypto = require('crypto');
const isValid = crypto.timingSafeEqual(Buffer.from(password), Buffer.from(confirmPassword));https://stackoverflow.com/questions/52775967
复制相似问题