XSS sanitization in backend and usage of DomPurify and jsdom with pocketbase #6694
-
|
Hello community, kindly seeking for guidance regarding a security issue and how to do html sanitization in the backend with pocketbase. What is the matter?Specifically I want to sanitize user input that might contain malicious code. I want to use JS hooks for this purpose. I can do this in the frontend, however I want to prevent, that by means of third party tools xss content could still be sent through the pocketbase API and enters the database, hence the next time the backend delivers this content to the client, XSS would be executed in the browser on the client. What would be the desired goal?Pocketbase either out-of-the-box or by implementing a hook, specifically How did this become a thing?Why does this content get rendered on the client? Because I have a rich editor field, where users essentially can create some formatted text and the html content would be rendered verbatim using v-html, but any other technology/tool like using What have I tried until this point?I tried to make use of DomPurify in the backend with pocketbase using hooks specifically to further strenghten the application and prevent xss code injection into my database. DomPurify explicitly describes it can be used on the server. However it also says on the server you would need jsdom to create a DOM of the to be sanitized content and then use DomPurify on it. DomPurify provides a cjs file, as I understood Pocketbase supports CommonJS only when using JS, I got that information from here https://pocketbase.io/docs/js-overview/#loading-modules Because Possible solutions I did think of
Thank you for your time and help, best regards Jacky |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
The PocketBase UI should be XSS free no matter what the user submits. We ensure this by serving a default Content Security Policy (CSP) and by minimize rendering untrusted raw HTML (we do render raw HTML as part of the TinyMCE preview but it is considered safe because it performs its own HTML sanitization and even if something manage to slip through it the CSP should catch it). Regarding If you really want to perform the sanitization on the server-side then I'd recommend using Go and the If you are working on a SPA I personally wouldn't do even that and instead will perform the sanitization in the browser right before passing it to |
Beta Was this translation helpful? Give feedback.
The PocketBase UI should be XSS free no matter what the user submits.
We ensure this by serving a default Content Security Policy (CSP) and by minimize rendering untrusted raw HTML (we do render raw HTML as part of the TinyMCE preview but it is considered safe because it performs its own HTML sanitization and even if something manage to slip through it the CSP should catch it).
Regarding
jsdom-jsdomalready seems to be a CJS module but it won't work with the PocketBasepb_hooksbecause it relies on Node.js specific APIs such aspath,fs,vm, etc. You can try searching for an alternative pure JS library but I would advice against it because usually html sanitization libraries are very co…