Hi all,
I don't work with Play myself, but in my free time I do some web
security related work and have reported issues to organisations such as
Curse, GitHub, ASK4, WBS/University of Warwick and others - some as part
of bug bounty schemes. I've noticed in the last few months that
applications built with Play tend to be very good when it comes to XSS
but are disproportionately vulnerable to cross site request forgery.
I've seen 3 or 4 like this, and most of them are still vulnerable.
A few days back I reported a couple of issues (including a CSRF) in an
open source Play project and was able to see the diff required
(
https://git.io/vMOxY) to stop the forms being vulnerable to a CSRF
attack. No less than 12 "@import views.html.helper.CSRF" lines, 25 "@
CSRF.formField" lines and an additional dependency that needed to be
added and configured. From what I understand, out of the box (activator
new test play-scala), Play applications are not secure against this sort
of attack. The cookes aren't SameSite=strict and POST requests are just
accepted. There's not even a Referer check. It's a ton of effort with
Play to fix these sorts of vulnerabilities and I can see why developers
don't bother, especially those that "just want to get things done".
Looking at Django for a moment, the CsrfViewMiddleware is activated by
default and the site is safe. The developer will immediately have their
POST/other unsafe requests fail if they neglect to include a token.
ASP.NET MVC Core automatically adds a "__RequestVerificationToken" to
all <form> elements and new project templates automatically include a
filter (AutoValidateAntiforgeryTokenAttribute) which causes unsafe
requests to have their token validated. Laravel's skeleton includes a
VerifyCsrfToken middleware class which is enabled by default.
Has there been any prior discussion on this? I believe the CSRF
protection should be on by default and opt-out (in the play-scala and
play-java seeds). I do understand that some developers will have no need
for this sort of protection (web APIs mostly), but they should have to
*consciously* opt out. I thought I'd flag this up in the hope of having
some discussion/potential behaviour changes.
Regards,
Adam