{"id":263444,"date":"2015-08-13T02:40:02","date_gmt":"2015-08-12T22:40:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=263444"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=263444","title":{"rendered":"Spring Security 4 + CSRF (\u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 Spring \u043f\u0440\u043e\u0435\u043a\u0442 \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442 \u043c\u0435\u0436\u0441\u0430\u0439\u0442\u043e\u0432\u043e\u0439 \u043f\u043e\u0434\u0434\u0435\u043b\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430)"},"content":{"rendered":"<p>     \t<img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/58e\/643\/b73\/58e643b730ad4cf5ae1bd8af29b29c96.jpg\"\/><\/p>\n<p>  \u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435!<br \/>  \u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0443\u044f\u0437\u0432\u0438\u043c\u044b\u043c, \u0435\u0441\u043b\u0438 \u0432 \u043d\u0435\u043c \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0437\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/\u041c\u0435\u0436\u0441\u0430\u0439\u0442\u043e\u0432\u0430\u044f_\u043f\u043e\u0434\u0434\u0435\u043b\u043a\u0430_\u0437\u0430\u043f\u0440\u043e\u0441\u0430\">\u041c\u0435\u0436\u0441\u0430\u0439\u0442\u043e\u0432\u043e\u0439 \u043f\u043e\u0434\u0434\u0435\u043b\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (CSRF)<\/a>. <br \/>  \u0412 Spring Security 4.x \u043e\u043d\u0430 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 <a href=\"http:\/\/docs.spring.io\/spring-security\/site\/migrate\/current\/3-to-4\/html5\/migrate-3-to-4-xml.html#m3to4-xmlnamespace-csrf\">\u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0441 Spring Security 3.x \u043d\u0430 4.x<\/a> \u0435\u0435 \u043d\u0430\u0434\u043e \u043b\u0438\u0431\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c  <\/p>\n<pre><code class=\"xml\">&lt;http&gt; \t... \t&lt;csrf disabled=&quot;true&quot;\/&gt; &lt;\/http&gt; <\/code><\/pre>\n<p> \u043b\u0438\u0431\u043e, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435 \u0438 \u0437\u0430\u0447\u0435\u0442\u043d\u0435\u0435, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0434\u0435\u043b\u0430\u043b \u044d\u0442\u043e \u0432 10-\u043c\u0438\u043d\u0443\u0442\u043d\u043e\u043c \u0432\u0438\u0434\u0435\u043e:<br \/>  <iframe loading=\"lazy\" width=\"560\" height=\"349\" src=\"\/\/www.youtube.com\/embed\/oPRFFXdgc6M?wmode=opaque\" frameborder=\"0\" allowfullscreen><\/iframe><br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f CSRF \u0432 \u043f\u0440\u043e\u0435\u043a\u0442:<\/h3>\n<p>  <\/p>\n<ol>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u044b: <a href=\"http:\/\/docs.spring.io\/spring-security\/site\/docs\/current-SNAPSHOT\/apidocs\/org\/springframework\/security\/web\/csrf\/CsrfFilter.html#setRequireCsrfProtectionMatcher-org.springframework.security.web.util.matcher.RequestMatcher-\">\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e CSRF \u0437\u0430\u0449\u0438\u0442\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 GET, HEAD, TRACE, OPTIONS<\/a>. \u042d\u0442\u043e \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u043b\u044f logout, \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u044b\u0439 \u0441\u0430\u0439\u0442 \u043c\u043e\u0433 \u0440\u0430\u0437\u043b\u043e\u0433\u0438\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441 POST.  <\/li>\n<li>\u0412\u043e \u0432\u0441\u0435\u0445 \u0444\u043e\u0440\u043c\u0430\u0445, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c submit, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u043f\u043e\u043b\u0435 name=_csrf \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c csrfToken. \u041f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 <a href=\"http:\/\/docs.spring.io\/spring\/docs\/current\/spring-framework-reference\/html\/view.html#view-jsp-formtaglib-formtag\">Spring\u2019s form tag library<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043a\u0440\u043e\u043c\u0435 \u0431\u0438\u043d\u0434\u0438\u043d\u0433\u0430 \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u043f\u0440\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u043c csrf \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442 \u0432 \u0444\u043e\u0440\u043c\u0443 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u043f\u043e\u043b\u0435.<br \/> \n<pre><code class=\"xml\">&lt;%@taglib prefix=&quot;form&quot; uri=&quot;http:\/\/www.springframework.org\/tags\/form&quot; %&gt; ... &lt;form:form method=&quot;post&quot; ...&gt;      ... &lt;\/form:form&gt; <\/code><\/pre>\n<p>  <\/li>\n<li>\u0414\u043b\u044f ajax \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 csrf \u0442\u043e\u043a\u0435\u043d \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a (header). <a href=\"http:\/\/docs.spring.io\/spring-security\/site\/docs\/current\/reference\/html\/csrf.html#csrf-include-csrf-token-ajax\">\u041f\u0440\u0438\u0447\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 ajax \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/a><br \/> \n<pre><code class=\"xml\">&lt;sec:csrfMetaTags \/&gt; <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"javascript\">var token = $(&quot;meta[name='_csrf']&quot;).attr(&quot;content&quot;); var header = $(&quot;meta[name='_csrf_header']&quot;).attr(&quot;content&quot;); $(document).ajaxSend(function(e, xhr, options) {     xhr.setRequestHeader(header, token); }); <\/code><\/pre>\n<p>  <\/li>\n<li>\u041d\u0430\u043a\u043e\u043d\u0435\u0446 \u0434\u043b\u044f stateless REST \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043ec\u0442\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u0449\u0438\u0442\u044b: <a href=\"http:\/\/blog.jdriven.com\/2014\/10\/stateless-spring-security-part-1-stateless-csrf-protection\/\">\u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u043d\u0435-JSON POST\/PUT\/DELETE<\/a><br \/> \n<pre><code class=\"java\">@RestController @RequestMapping(value = AdminRestController.REST_URL, consumes = MediaType.APPLICATION_JSON_VALUE) <\/code><\/pre>\n<p>  <\/li>\n<\/ol>\n<p>  <\/p>\n<h3>\u041d\u0443 \u0438 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u0442\u0435\u043c\u0443:<\/h3>\n<p>  <\/p>\n<ul>\n<li><a href=\"http:\/\/docs.spring.io\/spring-security\/site\/docs\/current\/reference\/html\/csrf.html#csrf-using\/\">Spring Security CSRF Protection<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/11008469\/are-json-web-services-vulnerable-to-csrf-attacks\">Are JSON web services vulnerable to CSRF attacks<\/a><\/li>\n<li><a href=\"https:\/\/ru.wikipedia.org\/wiki\/\u041f\u0440\u0430\u0432\u0438\u043b\u043e_\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f_\u0434\u043e\u043c\u0435\u043d\u0430\">\u041f\u0440\u0430\u0432\u0438\u043b\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u043c\u0435\u043d\u0430 (SOP)<\/a><\/li>\n<li><a href=\"https:\/\/ru.wikipedia.org\/wiki\/Cross-origin_resource_sharing\">Cross-origin resource sharing (CORS)<\/a><\/li>\n<\/ul>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0412\u044b \u0443\u0436\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u0438 \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0437\u0430\u0449\u0438\u0442\u0443 \u043e\u0442 CSRF \u0432 \u0412\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442.     \t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/264641\/\"> http:\/\/habrahabr.ru\/post\/264641\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t<img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/58e\/643\/b73\/58e643b730ad4cf5ae1bd8af29b29c96.jpg\"\/><\/p>\n<p>  \u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435!<br \/>  \u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0443\u044f\u0437\u0432\u0438\u043c\u044b\u043c, \u0435\u0441\u043b\u0438 \u0432 \u043d\u0435\u043c \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0437\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/\u041c\u0435\u0436\u0441\u0430\u0439\u0442\u043e\u0432\u0430\u044f_\u043f\u043e\u0434\u0434\u0435\u043b\u043a\u0430_\u0437\u0430\u043f\u0440\u043e\u0441\u0430\">\u041c\u0435\u0436\u0441\u0430\u0439\u0442\u043e\u0432\u043e\u0439 \u043f\u043e\u0434\u0434\u0435\u043b\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (CSRF)<\/a>. <br \/>  \u0412 Spring Security 4.x \u043e\u043d\u0430 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 <a href=\"http:\/\/docs.spring.io\/spring-security\/site\/migrate\/current\/3-to-4\/html5\/migrate-3-to-4-xml.html#m3to4-xmlnamespace-csrf\">\u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0441 Spring Security 3.x \u043d\u0430 4.x<\/a> \u0435\u0435 \u043d\u0430\u0434\u043e \u043b\u0438\u0431\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c  <\/p>\n<pre><code class=\"xml\">&lt;http&gt; \t... \t&lt;csrf disabled=&quot;true&quot;\/&gt; &lt;\/http&gt; <\/code><\/pre>\n<p> \u043b\u0438\u0431\u043e, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435 \u0438 \u0437\u0430\u0447\u0435\u0442\u043d\u0435\u0435, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0434\u0435\u043b\u0430\u043b \u044d\u0442\u043e \u0432 10-\u043c\u0438\u043d\u0443\u0442\u043d\u043e\u043c \u0432\u0438\u0434\u0435\u043e:<br \/>  <iframe loading=\"lazy\" width=\"560\" height=\"349\" src=\"\/\/www.youtube.com\/embed\/oPRFFXdgc6M?wmode=opaque\" frameborder=\"0\" allowfullscreen><\/iframe>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-263444","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/263444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=263444"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/263444\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=263444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=263444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=263444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}