Comments (1)
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)
- How to pass array and other values as param in Typescript? HOT 2
- Lack of documentation on serialization of custom Javascript HOT 2
- pg-native not wotks on Bun (same code works on Node.js) HOT 1
- Sample Error Event Handling Documentation Does Not Work HOT 2
- Doesn't work with next.js Edge runtime HOT 23
- [Question] - Best way to check pool health? HOT 6
- `\gexec` fails with `syntax error at or near "\"` HOT 4
- throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string') HOT 2
- [BUG] node-postgres query submit preparation takes a huge amount of time HOT 2
- Best SQL migration tool to be used along side `pg` HOT 1
- node-postgres 8.11.5 is not able to connect to AWS RDS Postgres 16.1 HOT 2
- Using pg-query-stream with query_timeout set, timeout timer doesn't get released HOT 1
- document how to run query and retrieve results HOT 8
- Passing in quoted tabled names for a create table query HOT 4
- SASL: Last message was not SASLResponse HOT 1
- Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string HOT 1
- SyntaxError: Cannot use import statement outside a module HOT 2
- I can't use parameters with more than a digit HOT 2
- bind message supplies 1 parameters, but prepared statement "" requires 8 HOT 2
- Inserting now() at time zone 'utc' gives invalid results HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-postgres.