Are JSON web services vulnerable to CSRF attacks?

Forging arbitrary CSRF requests with arbitrary media types is effectively only possible with XHR, because a form’s method is limited to GET and POST and a form’s POST message body is also limited to the three formats application/x-www-form-urlencoded, multipart/form-data, and text/plain. However, with the form data encoding text/plain it is still possible to forge requests … Read more

Same-Site flag for session cookie in Spring Security

New Tomcat version support SameSite cookies via TomcatContextCustomizer. So you should only customize tomcat CookieProcessor, e.g. for Spring Boot: @Configuration public class MvcConfiguration implements WebMvcConfigurer { @Bean public TomcatContextCustomizer sameSiteCookiesConfig() { return context -> { final Rfc6265CookieProcessor cookieProcessor = new Rfc6265CookieProcessor(); cookieProcessor.setSameSiteCookies(SameSiteCookies.NONE.getValue()); context.setCookieProcessor(cookieProcessor); }; } } For SameSiteCookies.NONE be aware, that cookies are also Secure … Read more

Rails CSRF Protection + Angular.js: protect_from_forgery makes me to log out on POST

I think reading CSRF-value from DOM is not a good solution, it’s just a workaround. Here is a document form angularJS official website http://docs.angularjs.org/api/ng.$http : Since only JavaScript that runs on your domain could read the cookie, your server can be assured that the XHR came from JavaScript running on your domain. To take advantage … Read more

Angular 6 does not add X-XSRF-TOKEN header to http request

The problem once again is Angular’s poor documentation. The fact is, Angular will add the X-XSRF-TOKEN header only if the XSRF-TOKEN cookie was generated server-side with the following options: Path = / httpOnly = false (this is very important, and fully undocumented) Besides, the Angular app and the URL being called must reside on the … Read more

Django CSRF framework cannot be disabled and is breaking my site

Yes, Django csrf framework can be disabled. To manually exclude a view function from being handled by any CSRF middleware, you can use the csrf_exempt decorator, found in the django.views.decorators.csrf module. For example: (see doc) from django.views.decorators.csrf import csrf_exempt @csrf_exempt def my_view: return Httpresponse(“hello world”) ..and then remove {% csrf_token %} inside the forms from … Read more