question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

We should highlight that using prisma.raw() with parameters is not secure and recommend using prisma.raw``

See original GitHub issue

Problem

Users are using prisma.raw() like

const data = await prisma.raw(
  `SELECT * FROM "ProviderItemAttribute" WHERE "provider_item" = ${root.id} AND "user" = ${auth.user.id} limit 1;`,
);

This example is using prisma.raw() the pure text version so there is no security around parameters.

Only raw`` is secure because it’s using https://github.com/blakeembrey/sql-template-tag

Solution

In this case it would be recommended to do

const data = await prisma.raw`
	SELECT * FROM "ProviderItemAttribute" WHERE "provider_item" = ${root.id} AND "user" = ${auth.user.id} limit 1;
`;

This should be highlighted in the docs (and examples?) We also can think about how to warn users that are using prisma.raw() or even disable it under a flag?

Note prisma.raw`` parameters do not work as of today with PostgreSQL see https://github.com/prisma/prisma-client-js/issues/595

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
steebchencommented, Jun 15, 2020

IMO, this is not just a docs issue – highlighting it in the docs is NOT enough. In fact, the current docs are long outdated, which shows how many users actually read them before using a feature. It’s not enough.

1reaction
pantharshit00commented, May 26, 2020

@alexvilchis Can you please open a new issue with a reproduction for that? That should not happen

Read more comments on GitHub >

github_iconTop Results From Across the Web

Raw database access (Reference) - Prisma
Learn how you can send raw SQL and MongoDB queries to your database using the raw() methods from the Prisma Client API.
Read more >
Prism
Prism is a lightweight, extensible syntax highlighter, built with modern web standards in mind. It's used in millions of websites, including some of...
Read more >
A Prisma ORM Review - HackerNoon
Prisma ORM is a good choice for your project. ... You have to define your models in a separate file and use specific...
Read more >
The best TypeScript ORMs - LogRocket Blog
Should we use ORMs in our TypeScript codebases? Picking the best TypeScript ORMs. Prisma; TypeORM; MikroORM; Sequelize; Objection.js. How to ...
Read more >
How To Build a REST API with Prisma and PostgreSQL
Prisma is an open source database toolkit. In this tutorial, you will build a REST API for a small blogging application in TypeScript...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found