Ruin9999
Ruin99992mo ago

What is a good way to implement user input sanitization (to prevent XSS)?

I've always been using dompurify to help with user input sanitization but it doesn't seem to work on the convex mutations. I think this could be because of the stripped down nodejs environment that convex uses. (Not sure if im right) What are some other ways that you guys have implemented user input sanitization? Right now I've got some basic santization by using regex to filter out html elements but I'm hoping to use an opensourced library instead so I don't have to always keep up to date with any XSS prevention changes.
14 Replies
Convex Bot
Convex Bot2mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
Sara
Sara2mo ago
Before I answer this question intensivly, what is the type of your input? is it supposed to be on doing something on your form or just passing in user Form? if you're doing something like a text editor, don't use dangersoulySetInnerHtml, I personally use Rehype, it does the work well for my use cases
Ruin9999
Ruin9999OP2mo ago
Its just text and im using Rehype along with react-markdown to render it.
Sara
Sara2mo ago
GitHub
GitHub - rehypejs/rehype-sanitize: plugin to sanitize HTML
plugin to sanitize HTML. Contribute to rehypejs/rehype-sanitize development by creating an account on GitHub.
Sara
Sara2mo ago
I've used this plugin before
Ruin9999
Ruin9999OP2mo ago
Ah this looks interesting
Sara
Sara2mo ago
yep, I think it would work well with your current plugin you just need to install it
Ruin9999
Ruin9999OP2mo ago
The examples provided look like they're all client side though. Do you know if this works on the server side as well? I haven't had much experience with these kinds of libraries
Sara
Sara2mo ago
it sure does rehype works on server and client side
Ruin9999
Ruin9999OP2mo ago
Oh that's amazing
Sara
Sara2mo ago
are using something else to render your mark down? like TipTap for instance usually they have stuff like that out of the box
Ruin9999
Ruin9999OP2mo ago
Nope just using simple react markdown to render everything https://www.npmjs.com/package/react-markdown/v/8.0.6
npm
react-markdown
React component to render markdown. Latest version: 10.1.0, last published: 4 months ago. Start using react-markdown in your project by running npm i react-markdown. There are 3718 other projects in the npm registry using react-markdown.
Ruin9999
Ruin9999OP2mo ago
Thank you for the help!
Sara
Sara2mo ago
looks good, good luck!

Did you find this page helpful?