【问题标题】:Third party access to attachments under the “readonly” Gmail scope第三方访问“只读”Gmail 范围内的附件
【发布时间】:2020-11-12 21:05:34
【问题描述】:

在“查看您的电子邮件和设置”下,“只读”范围内意外授予第三方应用程序访问我的 Gmail 的权限 https://www.googleapis.com/auth/gmail.readonly

这会让第三方能够直接从我的收件箱下载附件文件吗?

【问题讨论】:

    标签: gmail gmail-api attachment scopes


    【解决方案1】:

    是的,documentation 指定为https://www.googleapis.com/auth/gmail.readonly

    读取所有资源及其元数据

    拥有这些范围的人也可以访问您的附件,例如在他的驱动器上创建一个副本。

    您可以使用简单的 Apps 脚本代码轻松地自行测试。

    例如向自己发送一封带有附件的电子邮件并运行以下代码:

    function myFunction() {
      var blob = GmailApp.getInboxThreads()[0].getMessages()[0].getAttachments()[0].copyBlob();
      DriveApp.createFile(blob).setName("copied blob");
    }
    
    • 此代码将检索您最新收件箱消息的附件并将其保存在您的驱动器上。

    • 如果你继续Files -> Project Properties -> Scopes,你会看到脚本自动请求范围

      https://mail.google.com/

      https://www.googleapis.com/auth/drive

    • 但是现在,通过打开 manifest (View -> Show manifest file) 手动设置范围并硬编码 authorization scopes,例如:

    {  
      "oauthScopes": [
        "https://www.googleapis.com/auth/gmail.readonly",
        "https://www.googleapis.com/auth/drive"
      ],
      "timeZone": "Europe/Paris",
      "dependencies": {
      },
      "exceptionLogging": "STACKDRIVER",
      "runtimeVersion": "V8"
    }
    
    • 再次运行您的代码
    • 您会看到它仍然可以访问和保存附件 - 即使使用 https://www.googleapis.com/auth/gmail.readonly 范围!

    【讨论】:

    • 谢谢!我看到你也添加了驱动范围,这和只读范围一样有必要吗?还是仅使用只读范围而不使用驱动范围也允许访问附件?
    • 要访问附件,您只需要 gmail 只读范围。但在我提供的示例中,用户将附件保存在 Google 驱动器上(只是一个示例) - 这就是驱动器范围的用途。
    猜你喜欢
    • 2012-05-29
    • 1970-01-01
    • 2017-04-27
    • 2013-06-02
    • 1970-01-01
    • 1970-01-01
    • 2023-02-02
    • 1970-01-01
    • 2016-06-23
    相关资源
    最近更新 更多