Sanitizing POST requests with json data that has backslahes

Viewed 23

I'm doing the following in a rest API using ExpressJS:

app.use(express.json())

So I can accept JSON data.

I have routes and everything.

Using CURL, if I POST input like { "name" : "Bob", "password" : "ddd.\.\dd." }, to the /login route, the app crashes with an error message about the 'd' after the backslash. This is because the JSON request has dots or backslashes. Everything works fine if no backslash in the data.

Adding app.set('json escape',true); did not help.

How can I protect the API from such requests by escaping the password key? Thank you.

0 Answers
Related