You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It can be confusing for newer developers that these two are not the same:
// value is escapedqueryRaw`SELECT * FROM table WHERE col=${value}`// open to injectionqueryRaw(`SELECT * FROM table WHERE col=${value}`)
The same is true for $executeRaw. This is quite a dangerous mistake to make and so these functions should not be so close together, under the same name.
Suggested solution
Keep the tagged template literal and move $queryRaw() and executeRaw() to $dangerouslyQueryRaw() and $dangerouslyExecuteRaw() (as React has done with dangerouslySetInnerHTML).
Alternatives
Another thing worth considering is to remove the tagged template literal queryRaw because the "raw" already implies it is unsanitized. The sanitized tagged template literal could perhaps be moved under sql instead. The truly raw one could stay under queryRaw() or move to $dangerouslyQueryRaw().
Sidenotes
I know that queryRaw() is just the implementation of the tagged template literal, but it could still be moved to dangerouslyQueryRaw() and that could be the one recommended in the docs. The default implementation could also just return an error if used without any interpolation (although this would prevent people from using it even if they didn't have values to be sanitized).
Reacted by A., Angus Holder, Karl-Edward Jean-Mehu, Dick Fickling and Samuli Suomi
I agree with @cloudagon, However, renaming $queryRaw to $sql or sql can also cause some confusion considering that all the RDBMSs currently supported or will be supported has some variant of SQL. I believe simply rename it to $query is the best choice, especially considering that MongoDB support will hopefully be available and it does not use SQL whatsoever.
topic: raw$queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli
Activity
ae42faf7 commentedon May 15, 2021
Holy 💩, I had no idea
queryRaw()was unsafe.I like the suggested solution.
Karl-EdwardJeanMehu commentedon May 16, 2021
I agree with @cloudagon, However, renaming
$queryRawto$sqlorsqlcan also cause some confusion considering that all the RDBMSs currently supported or will be supported has some variant of SQL. I believe simply rename it to$queryis the best choice, especially considering that MongoDB support will hopefully be available and it does not use SQL whatsoever.pantharshit00 commentedon May 18, 2021
Looks like @matthewmueller opened a general issue on this topic so I referenced this there: #7142
matthewmueller commentedon Oct 6, 2021
This is done now