authentication - 如何为新用户帐户创建临时链接?
问题描述
我创建了需要用户身份验证的单页应用username
程序password
。系统中的每个帐户都是由管理员创建的。用户没有选项可以单击链接并创建帐户。在研究并寻找最佳解决方案后,我首先改变的是用户如何恢复密码的方式。这是有关该逻辑如何工作的简短架构。用户首先必须单击链接Forgot Password
输入他们的电子邮件并提交表单。他们将看到以下消息:
An email has been sent to example@gmail.com with further instructions.
将执行此过程的函数如下所示:
cfstoredproc( procedure="CheckEmail", datasource=dsn ) {
cfprocparam( maxlength=80, null=!len(trim(arguments.email)), cfsqltype="cf_sql_varchar", dbvarname="@Email", value=trim(arguments.email) );
cfprocresult( name="EmailResult" );
}
if( EmailResult.recordCount EQ 1) {
// Generate new token
local.newToken = createUUID();
// Build URL with token parameter and add hashed value
local.theUrl = "https://example.com/Reset.cfm?token=" & local.newToken;
// Set expiration time (30 minutes)
local.Expires = DateAdd("n", 30, now());
cfstoredproc( procedure="SaveToken", datasource=dsn ) {
cfprocparam( maxlength=80, null=!len(trim(arguments.email)), cfsqltype="cf_sql_varchar", dbvarname="@Email", value=trim(arguments.email) );
cfprocparam( maxlength=35, null=!len(trim(local.newToken)), cfsqltype="cf_sql_varchar", dbvarname="@Token", value=trim(local.newToken) );
cfprocparam( null=!len(trim(local.Expires)), cfsqltype="cf_sql_timestamp", dbvarname="@Expires", value=trim(local.Expires) );
cfprocresult( name="TokenResult" );
}
if ( len(TokenResult.RecID) ) {
savecontent variable="mailBody"{
writeOutput('<br>Here is your password reset link: <a href="' & theUrl & '">Click here</a> as soon as possible and change your password.<br>' );
}
local.mail = new mail();
// Set it's properties
local.mail.setSubject("Example Application");
local.mail.setTo(arguments.email);
local.mail.setFrom("noreply@example.com");
local.mail.setType("html");
// Send the email
local.mail.send(body = mailBody);
local.fnResults = {status : "200", message : "An email has been sent to <b>" & arguments.email & "</b> with further instructions."};
} else {
local.fnResults = {status : "400", message : "Error! Something went wrong."};
}
}else{
savecontent variable="mailBody"{
writeOutput('<br>We recieved a password reset request. The email you have provided does not exist in our system.<br>');
}
local.mail = new mail();
// Set it's properties
local.mail.setSubject("Example Application");
local.mail.setTo(arguments.email);
local.mail.setFrom("noreply@example.com");
local.mail.setType("html");
// Send the email
local.mail.send(body = mailBody);
local.fnResults = {status : "200", message : "An email has been sent to <b>" & arguments.email & "</b> with further instructions."};
}
然后下一步是如果电子邮件存在并且用户单击链接,我将显示他们可以输入新密码的表单,或者他们将看到消息This link has expired or does not exist anymore.
。以下是Reset.cfm
页面示例:
if (structKeyExists(url,"token") && isValid("uuid", url.token) && len(trim(url.token)) == 35){
cfstoredproc( procedure="CheckToken", datasource=dsn ) {
cfprocparam( maxlength=35, null=!len(trim(url.token)), cfsqltype="cf_sql_varchar", dbvarname="@Token", value=trim(url.token) );
cfprocresult( name="TokenResult" );
}
if( TokenResult.recordCount == 1 ){ //If token is valid (not expired) show the form.
<form name="frmRecovery" id="frmRecovery" autocomplete="off">
<input type="hidden" name="token" value="<cfoutput>#url.token#</cfoutput>">
<div class="form-group">
<div class="alert alert-info"><strong>Info!</strong> After saving your changes, you will be taken back to the login screen. Log into the system with the account credentials you have just saved.</div>
</div>
<div class="form-group">
<label class="control-label" for="password"><span class="label label-primary">Password</span></label>
<input type="password" class="form-control" name="frmRecovery_password" id="frmRecovery_password" placeholder="Enter Password" maxlength="64" required>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
<div class="form-group">
<div class="alert message-submit"></div>
</div>
</form>
}else{
<div class="alert alert-warning">
<strong>Warrning!</strong> This link has expired or does not exist anymore! </div>
}
}
如果用户被引导到表单输入密码,我将保存新密码并删除令牌。下一步是将他们引导到登录页面,他们可以输入凭据并登录。所以我的问题是当管理员创建新帐户时我可以使用类似的方法吗?管理员需要输入first
、last name
、username
等。然后单击Send Email
将转发username
和临时链接的按钮,新用户可以在其中输入密码并登录应用程序。之前使用的逻辑是生成临时密码,用户登录然后必须重置密码。我想知道我提出的解决方案是否有任何安全风险,或者与使用临时密码的解决方案一样好?
解决方案
您可以使用现有流程,前提是您还有一个用于添加用户信息的过程,但此处不存在。此外,您没有指定管理员将提供一封电子邮件,这显然对发送令牌很重要(除非用户名是电子邮件)。
为了提高安全性,取决于您想要的强化/安全程度,一些建议:
GUID/UUID 旨在是唯一的,但肯定不是不可猜测的。他们的目标是避免碰撞,而不是预测。如果你输出一组由coldfusion生成的UUID,你可以在某种程度上猜测一些可能的组合,以便假装重置过程,直到你找到一个 - 假设你有一个有效的UUID开始,在几百万左右(非常小的)。
这就是这种攻击的工作方式——您将为两个用户同时发送两个重置请求。一个是已知的(假设是一位拥有电子邮件但权限较低的员工)和一个未知的(假设是您无权访问其电子邮件的经理)。
您将在与经理(受害者)的重置密钥大致相同的时间为员工(攻击者)创建“种子”或已知 UUID。然后,您可以根据已知的 UUID 为该 UUID 块创建重置尝试。这样做不需要太多的处理能力或时间。
如果您改为创建 UUID 与随机生成/存储的盐组合的复合字符串(这将是您希望为用户记录存储的附加字段。) - 这将是最强的度量,因为它是唯一的并且可以不要用已知的密钥来猜测。
另一个是限制/限制对您的重置过程的请求(即 500 毫秒延迟等,用户看不到任何明显的差异,但严重限制了自动攻击的有用性)。
此外,您可以通过电子邮件或用户存储尝试,并阻止用户尝试过多的重置请求,并需要人工干预/另一种更仔细的解锁路径。
当然,您的密码也应该使用随机盐进行哈希处理。
不用说,要求强密码更安全。
推荐阅读
- sql-server - 在 SQL Server 中选择记录后更新记录
- python - 如何大写颠倒的元音?
- streaming - 检查点恢复时,flink kafkaproducer 以仅一次模式发送重复消息
- c# - 如何对齐两个元素与约束?
- apex - APEX CPU 限制。在顶点类中使用地图而不是列表
- python - python cgi PermissionError: [Errno 13] 权限被拒绝:
- ruby-on-rails - 当我尝试设置 Rails 项目时出了什么问题?
- c++ - 尝试读取 .txt 文件并根据用户输入的字母提取特定行
- r - 当模型包含交互时,mlogit 模型中的奇异性问题
- xamarin - Xamarin Forms Android 应用程序在启动时失败:无法检测 [class] 何时激活/停用..实现 IActivationForViewFetcher