Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC : How to Protect Application from CSRF and XSS

What is the best way to protect our Spring MVC application from CSRF and XSS.

Is there native Spring MVC support for this?

like image 530
Fitrah M Avatar asked Jan 17 '23 17:01

Fitrah M


2 Answers

In Spring:

Forms ( globally):

<context-param>
<param-name>defaultHtmlEscape</param-name>
<param-value>true</param-value>
</context-param>

Forms ( locally):

<spring:htmlEscape defaultHtmlEscape="true" />
like image 194
Liam Avatar answered Jan 31 '23 11:01

Liam


You can use Spring Security 3.2.0.RELEASE and enable csrf support with this configuration

<http>
    <!-- ... -->
    <csrf />
</http>
like image 36
iesen Avatar answered Jan 31 '23 09:01

iesen