Giter Club home page Giter Club logo

Comments (1)

brianc avatar brianc commented on June 13, 2024

Hey @mrmlnc - thanks for your thoughts & deep explanation & research into this! First of all, if at all possible, I highly recommend you use parameterized sql statements over using escapeLiteral, then you can have PostgreSQL backend do the escaping for you! You can use jsonb params for every param in your query if you want. I've written utility functions that will build a dynamic insert statement with parameters based on an arbitrary number of jsonb values to be inserted. Postgres supports unsigned int16 (~32k) parameters per query so you have quite a bit of headroom. Surprisingly I've sent megabytes of parameters in a single upsert statement to a postgres backend and it handles it without even a hiccup.

If escaping isn't possible for some reason then I your best bet is to bite the bullet & use the actual implementation of escapeLiteral in this project & eat the performance overhead. My gut is telling me there's probably an architectural decision you could change to work around things. Either change the queries so they are parametrizable or limit input size or maybe just yolo and don't worry about query speed if your system isn't under heavy load?

While I'm not a leading expert on sql injection I'm curious how your faster version using would avoid someone literally substituting the $__pg__$ into their input and therefore escaping out and then having a sql injection vector? If you are comfortable with that in your system (perhaps sanitizing input before escaping it w/ escapeLiteral in some way) then I think your best bet might to be to take that function you put in your comment & include it into your own codebase as a utility function for the one off situations where you have very very large unsanitized or partially trusted text input that needs to be escaped...I'm not willing to change the implementation of escapeLiteral as its as best we could do a 1 to 1 port of the C code in libpq that does the same thing. The security impact could be disastrous for a small potential performance gain in a rather edge-case scenario.

from node-postgres.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.