谷歌应用程序中的安全性脚本公共HTMLService,每个请求都有新的Utilities.getUuid()

时间:2018-04-03 03:01:50

标签: security authentication google-apps-script

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

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

  1. 访问网址(通过电子邮件共享的网址 - 这是一个小社区,并且不需要域名),系统会向用户显示使用HTMLService(doGet)生成的登录表单。
  2. 表单发布数据(doPost)和用户名&密码将根据电子表格中的值进行检查(TODO:将来密码密码)。
  3. 如果匹配,则使用 Utilities.getUUID()调用生成UUID字符串。该字符串存储在电子表格中。
  4. 然后该脚本生成并返回 jQuery Mobile 网站,其中包含 HTMLService 。所有页面都是一次性提供的,因为它们使用jQm页面导航。
  5. 这是服务电话:

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

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

    1. 后续每次调用后端来获取或设置数据均使用 google.script.run 。这总是调用相同的函数,并传递和对象:
      • 要调用的实际函数
      • 该功能所需的数据
      • 每次通话的用户名和最新UUID。
    2. 首先,检查用户名和UUID,如果匹配,则生成新的UUID并存储在电子表格中。
    3. 然后调用实际函数,并且 - 与返回的数据一起 - 将UUID发送到成功处理程序:
    4. 将调用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"]);
      }
      
      1. 如果由于某种原因导致之前的UUID不匹配,则会将其删除,然后用户要求再次登录。
      2. 虽然我相信通过这个计划,我可以防止社区成员的愚蠢或好奇(毕竟他们是忙碌的牙医,他们需要这个工作!)我担心的是在网址泄漏的情况下的攻击。我考虑使用谷歌或Facebook连接API,但由于其他原因,它是不可行的。 HTTPS是否保证了该方案的安全性? 我的实施中是否存在巨大且令人尴尬的漏洞?

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

0 个答案:

没有答案