如何通过 Node.js 保护敏感图像/文件免遭直接 URL 访问

发布于 2025-01-18 17:26:12 字数 392 浏览 6 评论 0原文

各位开发人员大家好,

我在 NodeJS 中遇到了一个(至少对我来说)具有挑战性的问题。我将非常感谢一些帮助。

考虑一个带有 NodeJS 后端和 MariahDB-DB 的 React 社区 Web 应用程序。每个用户都可以在他或她的个人相册中上传照片或视频。 仅允许登录用户查看。

现在,乍一看实施起来并不困难。但问题来了:

一旦登录用户看到图像 URL,他或她就可以直接通过浏览器访问图像/文件,甚至将其转发给未经授权的人员。

为了获得解决这个问题的灵感,我研究了 Instagram 的做法,他们似乎在图像中附加了某种哈希值。但我还没有找到有关该技术的更多信息。

那么,问题是:如何防止未经授权的直接访问?什么是最佳实践?

预先非常感谢,

Wiwi

Hello fellow developers,

I am stuck with a (at least to me) challenging problem in NodeJS. I would greatly appreciate some help.

Consider a community webapp in React with a NodeJS-Backend and a MariahDB-DB. Each user can upload photos or videos in his or her personal album.
Only logged-in users are allowed to see it.

Now, the implementation is not hard on first view. But here comes the problem:

Once an logged-in user is shown the image-URL, he or her can access the image/file directly through the browser and even forward it to unauthorized persons.

To get some inspiration to solve this I have looked how Instagram does ist and they seem to append some kind of hash to their images. But I have not found further information about that technique.

So, the question is: How can I prevent unauthorized direct access? What are best-practices?

Thanks so much in advance,

Wiwi

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文