我可以限制未经身份验证的用户访问 _all_docs 吗?

发布于 2024-10-16 21:02:57 字数 88 浏览 5 评论 0原文

我希望人们能够使用带有随机 ID 的链接私下共享文档,就像我将私人链接发布到 Pastebin 后得到的那样。我想总体了解 CouchDB 和 Cloudant。

I'd like people to be able to share documents privately, using a link with a random id, like I get after posting a private link to a pastebin. I want to know both for CouchDB and Cloudant in general.

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

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

发布评论

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

评论(1

锦上情书 2024-10-23 21:02:57

对于 Apache CouchDB,读取权限是针对每个数据库的,而不是针对每个文档。如果用户可以从数据库中获取文档,则用户也可以获取 _all_docs?include_docs=true

我在这个问题中写了关于CouchDB读取授权的详细信息。

有几种方法:

  1. 第 7 层防火墙或反向 HTTP 代理。这很难正确地做到; IMO 对大多数人来说不可行。您必须非常熟悉 CouchDB 的 API,以确保阻止每个可能的查询(例如,_rewrite 绕过您的过滤器)。

  2. 每个用户一个数据库。这是CouchDB 的原生解决方案。创建数据库非常便宜。然后,将用户可以看到的文档复制到他或她的数据库中。用户需要 Couch 上的密码或 OAuth 帐户。

  3. 我最近在每用户数据库方面取得了成功,但 URL 中还有一个唯一的密钥,可以让他们立即访问。这感觉就像你想要的东西,但在幕后我只是用随机密码创建一次性帐户。该链接会转到公共页面,例如 www.example.com/pastebin/index.html?doc_id=some_docid&secret=random_secret。然后浏览器上的 Javscript 将读取 window.location 并将该密码插入到 AJAX 查询中(在授权标头中)。沙发授予许可,用户很高兴。不幸的是,这需要一些尝试和错误。不过,这主要是简单的 Web 编程。

With Apache CouchDB, read permission is per-database, not per-document. If a user can fetch a document from a database, the user can fetch _all_docs?include_docs=true too.

I wrote details in this question about CouchDB read authorization.

There are a few approaches:

  1. Layer-7 firewall or reverse HTTP proxy. This is hard to do correctly; IMO not feasible for most. You must be very familiar with CouchDB's API to be sure every possible query is blocked (e.g. _rewrite going around your filter).

  2. One database per user. This is CouchDB's native solution. Creating databases is very cheap. Then, replicate the documents the user can see to his or her database. The user needs a password on the Couch, or an OAuth account.

  3. I have had success recently with per-user databases but also a unique key in the URL that grants them immediate access. It feels like the thing you want, however under the hood I am just creating throwaway accounts with random passwords. The link goes to a public page such as www.example.com/pastebin/index.html?doc_id=some_docid&secret=random_secret. Then Javscript on the browser will read window.location and insert that password into the AJAX query (in an Authorization header). Couch grants permission and the user is happy. Unfortunately, this required a little bit of trial and error; however it's mostly simple web programming.

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