我正在使用 Prisma
我有一个要搜索的 postgres 表,只查找与 (id 和 accessKey) 或 (id 和 OwnerId) 匹配的记录
如果 accessKey 或 OwnerId 未定义,它会不断查找位置 (id)
我发现如果我使用不可能的字符串,那么搜索就会起作用
我在 prisma 文档中找不到合适的答案,所以我想我会在这里问
return await db.attendee.findFirst({
where: {
OR: [
{ AND: { id, ownerId } },
{ AND: { id, accessKey } },
]
}
})
Run Code Online (Sandbox Code Playgroud)
如果 accessKey 或 OwnerId 未定义,那么它们实际上会从查询中消失,这是有道理的
我使用了这个并且它起作用了——这些值是 guid 的,所以它们永远不会匹配,但是如果我的秘密短语松动了(它在存储库中,而不是在环境变量中),那么这将是类似于 sql 注入的漏洞。 。
const userId = context?.currentUser?.sub || `can't touch this`;
const accessKey = vaccessAuth?.accessKey || `can't touch this`;
Run Code Online (Sandbox Code Playgroud)
还有什么更“棱镜方式”呢?
prisma ×1