您可以从 Google App Script UrlFetchApp 请求中检索到的 ID 是什么?

问题描述 投票:0回答:1

一个非常简单的问题。

什么是

UAEmdDd8-EFiXubNCcQqNSsoe9JR3TFSawg
User-Agent: Mozilla/5.0 (compatible; Google-Apps-Script; beanserver; +https://script.google.com; id: UAEmdDd8-EFiXubNCcQqNSsoe9JR3TFSawg)
ID,可以从 Google App Script
UrlFetchApp
请求中获得?

背景

我想限制来自 Google App Script 请求以外的任何客户端对我的服务器的请求,我决定分析来自 Google App Script UrlFetchApp 请求的请求标头,我得到了这个结果(使用 NGROK)。

Host: dbc2-103-154-151-44.ngrok.io
User-Agent: Mozilla/5.0 (compatible; Google-Apps-Script; beanserver; +https://script.google.com; id: UAEmdDd8-EFiXubNCcQqNSsoe9JR3TFSawg)
Accept-Encoding: gzip, deflate, br
X-Forwarded-For: <hidden>
X-Forwarded-Proto: http

我决定使用User-Agent来限制其他请求,但是我对所讨论的ID是否是脚本文件的唯一标识符有疑问

google-apps-script google-cloud-platform http-headers user-agent
1个回答
0
投票

之前调查过UrlFetchApp的

User-Agent
。在那种情况下,我了解到像
UAEmdD###
这样的
UAEmdDd8-EFiXubNCcQqNSsoe9JR3TFSawg
的值似乎是取决于Google Apps Script项目的唯一值。例如考虑以下情况。

  1. 新建一个standalone类型的Google Apps Script项目,使用UrlFetchApp,

    User-Agent
    如下

     Mozilla/5.0 (compatible; Google-Apps-Script; beanserver; +https://script.google.com; id: {###ID1###})
    
  2. 新建一个standalone类型的Google Apps Script项目,使用UrlFetchApp,

    User-Agent
    如下

     Mozilla/5.0 (compatible; Google-Apps-Script; beanserver; +https://script.google.com; id: {###ID2###})
    
  3. 在Google Spreadsheet上新建一个容器绑定脚本类型的Google Apps Script项目,使用UrlFetchApp,

    User-Agent
    如下

     Mozilla/5.0 (compatible; Google-Apps-Script; beanserver; +https://script.google.com; id: {###ID3###})
    

在这里,似乎在同一个Google Apps Script项目中使用UrlFetchApp时,始终使用相同的

User-Agent
{###}

从这种情况来看,例如,当您希望在服务器端仅允许

User-Agent
来自特定Google Apps Script项目的请求时,请设置像
Mozilla/5.0 (compatible; Google-Apps-Script; beanserver; +https://script.google.com; id: {###ID###})
这样的值。这样,只有特定的 Google Apps 脚本项目才能访问服务器。

另一方面,当您想要通过

User-Agent
允许来自Google Apps脚本项目的请求时,请通过删除ID来设置像
Mozilla/5.0 (compatible; Google-Apps-Script; beanserver; +https://script.google.com
这样的值。这样,只有使用 UrlFetchApp 的用户才能访问服务器。

注:

  • 我不确定在以后的更新中是否更改了此规范。所以,当您确认
    User-Agent
    的限制不是您设置后的预期结果时,请再次确认
    User-Agent
    的值。
© www.soinside.com 2019 - 2024. All rights reserved.