Skip to content

anilpank/oldWebAppCsrfProtection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

oldWebAppCsrfProtection

Protecting an old java based web application from csrf attacks

Many of the older java/j2ee based web applications that we end up working on/maintaining on, are not on latest spring or play or other cool frameworks which have automatic csrf protection features.

If you are one of those, worry not, simple Servlet Filters and some javascript is all that you need. Add below 2 filters in your web.xml

In all forms/wherever you are doing post requests inject a hidden field called csrfToken, Populate it's value by reading it from cookie. Sample example of jsp page where there is a form [SampleForm.jsp] (https://github.com/anilpank/oldWebAppCsrfProtection/blob/master/WebContent/SampleForm.jsp)

And a sample implementation of reading cookie value of csrfToken using javascript [CookieReader.js] (https://github.com/anilpank/oldWebAppCsrfProtection/blob/master/WebContent/CookieReader.js)

Brought to you by OjbLabs

About

Protecting an old java based web application from csrf attacks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published