在JavaScript中访问GitHub秘密

发布于 2025-02-07 17:02:38 字数 217 浏览 1 评论 0原文

我有一个与API互动的学校项目的网页。当前,API密钥保存在JavaScript文件中,我意识到这是安全风险。我将价值存储在一个github的秘密中;我对如何使用github workflows使其成为环境变量有一个粗略的想法,但绝对不知道如何在JavaScript中访问它。我该怎么办?

该项目完全是前端,并使用普通的JavaScript(以及被授予);我不知道如何做任何比API所说的更复杂的后端事情。

I have a webpage I made as a school project that interacts with an API. Currently, the API key is saved in the JavaScript file, which, I realize, is a security risk. I stored the value in a GitHub secret; I have a rough idea of how to make it an environment variable using GitHub workflows, but absolutely no idea how to access it in the JavaScript afterwards. How do I do so?

The project is entirely front-end and built with plain JavaScript (and jQuery, granted); I have no idea how to do any backend stuff more complicated than the API calls themselves.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

波浪屿的海角声 2025-02-14 17:02:38

因此对于任何仅浏览您的代码的人来说,它都不可见。

不幸的是,在此处使用GitHub Actions的秘密以进行安全性没有太多意义 - 使令牌无法源源控制, API密钥将需要在用户浏览器的代码中的某个位置。

即使您以某种方式将其混淆,他们也能够使用浏览器的网络检查器查看API键。

There is unfortunately not much point in using GitHub Actions' secrets here for security - for keeping the token out of source control, so it's not immediately visible for anyone just browsing your code, sure, but beyond that:

If your project is frontend only, the API key will need to be somewhere in the code served to the user's browser.

Even if you'd obfuscate it somehow, they'd be able to use the browser's network inspector to see the API key.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文