r/javahelp • • 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

24 Upvotes

9 comments sorted by

View all comments

8

u/Sheldor5 May 30 '21 edited May 31 '21

as long as you don't directly "execute" the user input there is nothing you have to worry about

I guess you are looking for Authentication and Authorization ... just google Spring Security

5

u/nutrecht Lead Software Engineer / EU / 20+ YXP May 31 '21

as long as you don't directly "execute" the user input there is nothing you jave to worry about

If he's just saving anything the client sent to him in his database he DEFINITELY has stuff to worry about.

1

u/Sheldor5 May 31 '21

like what?

what's so dangerous about GSON serializer and VARCHAR columns? its just text and no SQL Injection or Rhino Script execution ...

1

u/nutrecht Lead Software Engineer / EU / 20+ YXP May 31 '21

Missed the bit about him using elastic search?

1

u/Sheldor5 May 31 '21

uh yes ...