英文:
Do I need Contentful API key in runtime?
问题
作为一名DevOps工程师,我有一个使用Contentful的JavaScript应用程序。在构建过程中,我需要一个API密钥来获取一些预编译的静态数据,并将其保存在输出目录中,以及构建的其余代码一起。
这个API密钥似乎是一个秘密,在构建时保持安全不是问题。
但是在运行时,代码在浏览器中执行,这个密钥必须存在。直接交到一个[敌对的]用户手中。
因此,我有两个问题:
- 在运行时是否有必要使用API密钥?或者构建时是我们最后一次使用Contentful端点?
- 对于用户通过浏览器开发工具访问我们的API密钥是否安全?Contentful是否包含并提供给拥有密钥的人任何安全敏感数据?
英文:
As a DevOps guy, I've got a JavaScript application, that uses Contentful. During the build time I need an API Key to get some pre-compiled static data and save it in an output directory along with the rest of the built code.
This API key seems to be a secret and it is not a problem to keep it safe while building.
But during the run time code is executed in a browser and this key has to be there. Right in hands of a [hostile] user.
Thus, I have two questions:
- Is it a necessity to use an API key in a runtime? Or build time is the last time we use Contentful endpoint?
- Is it safe for us that a user has access to the our API key via browser devtools? Is there any security-sensitive data that Contentful holds and withdraws to those who possess the key?
答案1
得分: 1
以下是翻译好的内容:
问题是,什么密钥进入浏览器。 Contentful 有各种 API。 主要的是 Content Delivery API、Content Preview API 和 Content Management API。
只读的Content Delivery API(CDA) 返回已发布的内容。 如果您遵循最佳实践并没有将敏感信息放入 Contentful 中,那么将其公开仅计入 API 限制,以防有人查询您的公开可用内容。 许多人以这种方式使用公共密钥来为其前端提供动力。
只读的Content Preview API(CPA) 返回草稿内容。 虽然不是一件大事,但在公开环境中使用 CPA 密钥有点棘手,因为人们可以窥探您的未发布内容。 通常,CPA 密钥有点隐藏,或者通过标志进行控制,以避免这种情况发生。
读/写的Contentful Management API(CMA) 允许您创建/更改/更新内容。 人们使用它来构建自定义编辑界面或在规模上执行内容迁移。 CMA 密钥永远不应该公开,因为它们通常与用户的访问权限绑定。
英文:
The question is, what key makes it into the browser. Contentful has various APIs. The main ones are the Content Delivery API, Content Preview API and Content Management API.
The readonly Content Delivery API (CDA) returns already published content. If you're following best practices and didn't put sensitive info into Contentful having it public only counts towards the API limits in case someone queries your publicly available content. Many people use a public key to power their frontends in exactly this way.
The readonly Content Preview API (CPA) returns draft content. While not a massive deal, having a CPA key in public is a little tricky because people could snoop around your unpublished content. Usually, CPA keys are somewhat hidden or gated by a flag to avoid this situation.
The read/write Contentful Management API (CMA) allows you do create/change/update content. People use it to build custom editing UIs or perform content migrations at scale. CMA keys should never make it to the public because they're usually bound to the user's access rights.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论