【问题标题】:Only allow read if user has exact document id postgresql row level security/supabase仅当用户具有确切的文档 ID postgresql 行级安全性/supabase 时才允许读取
【发布时间】:2022-11-02 20:36:05
【问题描述】:

有没有办法让用户只有在拥有确切的文档 ID 时才能阅读文档?

我想避免创建用户,因此唯一的安全措施是保存在浏览器内存中的随机 guid - 设置将保存在 id=guid 的“设置”表中。

因此,当页面打开时,它将获取

supbase.from('settings').select('*').eq('id', guid)

如何保护该设置(不创建(虚拟)用户)

像这样在 Firebase 中: Firebase firestore only allow read if user has exact document ID 但对于 postgresql/supabase

【问题讨论】:

  • 这个“用户有办法......”和这个“我想避免创建用户......”是相互矛盾的。此外,您必须是某个用户才能连接到 Postgres。您将需要更详细地描述您要达到的目标。
  • @AdrianKlaver 和 Supabase 的连接用户是 anonauthenticated。问题归结为:有没有办法让anon 读取记录ID 已知的行,但阻止选择所有行。
  • 我不知道。

标签: postgresql row-level-security supabase supabase-database


【解决方案1】:

这是可行的,但我会:

  1. 禁止anon 用户通过 RLS 访问表(从 RLS 策略返回 false)
  2. 使用security definer 编写一个postgres 函数,该函数将uuid 作为参数,并且仅根据该参数从表中返回一行。 (如果该行不存在,则不返回任何内容)
  3. 使用 supabase .rpc() 格式调用函数。

【讨论】:

    猜你喜欢
    • 2021-06-22
    • 1970-01-01
    • 2019-03-30
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    • 2019-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多