Google Apps脚本中的安全性为每个请求提供了带有新Utilities.getUuid()的公共HTMLService脚本

twe*_*one 5 javascript security authentication web-applications google-apps-script

我生命中stackoverflow中的第一个问题!

我来自嵌入式程序设计领域,并且对Web安全性有非常肤浅的了解。我已经使用Google Apps脚本构建了平台。所有数据均存储在数据表中。一切正常。我很快想到了这种身份验证方案,说实话,我确定它一定是不安全的!绝对,我想念一些东西!这是我的过程:

  1. 在访问url(通过电子邮件共享的url-一个很小的社区,并且不需要该域名)后,系统会向用户显示使用HTMLService(doGet)生成的登录表单。
  2. 该表单将发布数据(doPost),并根据电子表格中的值检查用户名和密码(TODO:将来对密码进行哈希处理)。
  3. 如果匹配,则通过Utilities.getUUID()调用生成UUID字符串。该字符串存储在电子表格中。
  4. 然后,脚本生成并返回带有HTMLServicejQuery Mobile网站。所有页面均使用jQm页面导航,因此可同时提供。

这是服务电话:

var addedContent = '<script>var session={sessionId="UUID"}</script>';
return HtmlService.createTemplateFromFile... ...addedContent(addedContent);
Run Code Online (Sandbox Code Playgroud)

我使用.addedContent()调用将UUID字符串附加为javascript变量,该变量是在成功登录后使用Utilities.getUuid()生成的。

  1. 随后每次调用后端以获取或设置数据都通过google.script.run进行。这总是调用相同的函数,并通过和传递对象:
    • 实际要调用的功能
    • 该功能所需的数据,
    • 每个通话的用户名和最新的UUID。
  2. 首先,检查用户名和UUID,如果它们匹配,则生成一个新的UUID并将其存储在电子表格中。
  3. 然后调用实际函数,并将UUID与返回的数据一起发送给成功处理程序:

会调用google.script.run async的函数示例:

function get_user(username){
  ...
  var session = {username: username, sessionId: lastUUID};
  // don't confuse the two username properties.
  // the username for the authentication is inside the session object.
  // the property 'username' of the data object is for the getUser function
  // which will be called in the server script. Also the "getUser" is not
  // the actual function name either: it will be switched with the real one.
  var data = {
    auth: session,
    action: "getUser",
    username: username
  };
  ...
  google.script.run
    .withSuccessHandler(get_user_success) 
    .withFailureHandler(get_user_failure)
    .switchboard(data);`
}
Run Code Online (Sandbox Code Playgroud)

在服务器中:

function switchboard(data){
  var result = {sessionId: false};
  var action = data["action"];
  //
  var auth = authenticate(data["auth"]);
  // authenticate returns the new uuid string upon match or
  // deletes previous uuid and returns false
  if (auth == false) return result;
  switch(action){
    ...
    case 'getUser': response = the_real_function_name(data); break;
    ...
  }
  result = { sessionId: auth, response: response };
  return result;
  // so, what the page gets back is and object with the new uuid string
  // for the next call, and the actual requested data
}
Run Code Online (Sandbox Code Playgroud)

成功后:

function get_user_success(data){
  // data = {sessionId: "uuidstring", data: obj}
  sessionId = data["sessionId"] // new uuid string for subsequent calls
  ...
  $("some#element").val(data["data"]["address"]);
}
Run Code Online (Sandbox Code Playgroud)
  1. 如果由于某种原因前一个UUID不匹配,则将其删除,然后用户要求再次登录。

尽管我相信使用此方案可以防止社区成员的愚蠢或好奇(毕竟,他们是忙碌的牙医,他们需要这种工作!),我担心如果URL泄漏,就会受到攻击。我已经考虑过使用Google或Facebook Connect API,但由于其他原因,这是不可行的。HTTPS是否保证此方案的安全性?我的实施过程中是否存在巨大且令人尴尬的漏洞?

PS我试图在这里和其他地方搜索解决方案,但我所能找到的却是相反的:Google Apps脚本如何向第三台服务器进行身份验证-我找不到有人提供具有匿名执行权的GAS Web应用程序的解决方案,身份验证。