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

我来自嵌入式编程世界,我对网络安全有非常肤浅的了解 . 我使用 google apps script 构建了一个平台 . 所有数据都存储在数据表中 . 一切都很好 . 我很快就提出了这种认证方案,老实说,我确信它必须是不安全的!当然,我想念一些东西!这是我的过程:

  • 在访问网址时(通过电子邮件共享的网址 - 它是一个小社区,它不需要域名),会向用户显示使用HTMLService(doGet)生成的登录表单 .

  • 表单发布数据(doPost),并根据电子表格中的值检查用户名和密码(TODO:将来散列密码) .

  • 如果匹配,则使用 Utilities.getUUID() 调用生成UUID字符串 . 该字符串存储在电子表格中 .

  • 然后脚本生成并返回 jQuery Mobile 网站 HTMLService . 所有页面都是一次性提供的,因为它们使用jQm页面导航 .

这是服务电话:

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

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

  • 后续每次调用后端来获取或设置数据都是 google.script.run . 这总是调用相同的函数,并传递和对象:

  • 要调用的实际函数,

  • 该函数所需的数据,

  • 每次通话的用户名和最新的UUID .

  • 首先,检查用户名和UUID,如果匹配,则生成新的UUID并存储在电子表格中 .

  • 然后调用实际函数,并且 - 与返回的数据一起 - 将UUID发送到成功处理程序:

将调用google.script.run异步的函数示例:

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);`
}

在服务器中:

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
}

成功后:

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"]);
}
  • 如果由于某种原因导致先前的UUID不匹配,则将其删除,然后用户要求再次登录 .

虽然我相信通过这个计划,我可以防止社区成员的愚蠢或好奇(毕竟他们是忙碌的牙医,他们需要这个工作!)我担心的是在网址泄漏的情况下的攻击 . 我考虑使用谷歌或Facebook连接API,但由于其他原因,它是不可行的 . HTTPS是否保证了该方案的安全性?我的实施中是否存在巨大且令人尴尬的漏洞?

附:我试图在这里和其他地方搜索解决方案,但我能找到的却是相反的:谷歌应用程序脚本如何向第三台服务器进行身份验证 - 我无法找到有人为具有匿名执行权限和身份验证的GAS webapp提供服务的解决方案 .