My NodeJS server receives user input (a string) that may or may not contain double- or single quotes. I would like to prevent users from breaking out of the string by putting " or ' into their input, but they must retain the ability to use said characters. How can I achieve this in NodeJS?
EXAMPLE:
// Replace "break" with some malicious code
let unfilteredInput = "I am a hacker and I will "break" out of this string! Muhahahaha!"
// I would like to "sanitize" the input so it turns into this
let filteredInput = "I am a hacker and I will \"break\" out of this string! Muhahahaha!"
// Here, the hacker was unable to run their code as the string was "sanitized".
// This must happen server-side and not client-side to prevent tampering.
Thanks!