r/javahelp • u/CPU-overheat • May 30 '21
Codeless How to protect a spring boot API
Hi All,
Long time lurker here.
So I’ve been slowly learning Spring and I’m at the point where I have my spring boot api that uses elastic search, Auth0 and mongo and I’m pretty happy.
Now this API is still pretty basic, it allows users to post content almost like a blog article and retrieve their posts.
Now I’ve a question, I want to make sure I’m not open to any security issues like XSS attacks and the likes.
Can someone here recommended how I should do this? Basically for instance, one of my controllers accepts a DTO (JSON) and I want to sanitise the inputs as really you can post anything to the endpoint and it will just save it on Mongo. If it helps I’m using Mongo operations rather than JPA Repository
The closet I came on Google was a baledung article using OWASP esapi but that seems way outdated now.
Any help would be must appreciated
1
u/[deleted] May 31 '21
If you are just looking to sanitize-validate inputs before inserting into mongoDB then you can do bean validation (JSR-380).https://www.baeldung.com/javax-validation