{"id":470145,"date":"2025-08-09T15:00:23","date_gmt":"2025-08-09T15:00:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=470145"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=470145","title":{"rendered":"<span>CORS \u0434\u043b\u044f \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0439 \u0438 \u0440\u0430\u0431\u043e\u0442\u044b<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>\u0415\u0441\u043b\u0438 \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435 \u044d\u0442\u0443 \u043e\u0448\u0438\u0431\u043a\u0443 \u2014 \u0432\u044b \u043d\u0435 \u043e\u0434\u0438\u043d\u043e\u043a\u0438:<\/strong><\/p>\n<pre><code class=\"typescript\">Access to fetch at 'https:\/\/api.site.com' from origin 'http:\/\/localhost:3000'  has been blocked by CORS policy.<\/code><\/pre>\n<p><strong>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0438 \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u0447\u0438\u043d\u0438\u0442\u044c. \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 CORS, \u0438 \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d \u043d\u0443\u0436\u0435\u043d.<\/strong><\/p>\n<h2>1.\u00a0\u00a0\u00a0\u00a0 \u0417\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u0435\u043d CORS? \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c!\u00a0<\/h2>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0430\u0442\u0430\u043a\u0438:<\/strong><\/p>\n<ol>\n<li>\n<p>\u0412\u044b \u0432\u043e\u0448\u043b\u0438 \u043d\u0430\u00a0<a href=\"http:\/\/bank.com\" rel=\"noopener noreferrer nofollow\">bank.com<\/a>. \u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0441\u044c \u0432 \u043a\u0443\u043a\u0430\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0445\u043e\u0434\u0438\u0442\u0435 \u043d\u0430\u00a0<a href=\"http:\/\/evil.com\" rel=\"noopener noreferrer nofollow\">evil.com<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0430\u0439\u0442\u00a0<a href=\"http:\/\/evil.com\" rel=\"noopener noreferrer nofollow\">evil.com<\/a>\u00a0\u0442\u0430\u0439\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u00a0Get \/<strong>api\/account<\/strong> \u043d\u0430\u00a0<a href=\"http:\/\/bank.com\" rel=\"noopener noreferrer nofollow\">bank.com<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0411\u0440\u0430\u0443\u0437\u0435\u0440 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u0443\u043a\u0438 \u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0443 \u043d\u0430\u00a0<a href=\"http:\/\/bank.com\" rel=\"noopener noreferrer nofollow\">bank.com<\/a> \u2192 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0447\u0435\u0442\u0430 \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0434\u0435\u043d\u044c\u0433\u0438.<\/p>\n<\/li>\n<\/ol>\n<h2>2.\u00a0\u00a0\u00a0\u00a0 \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 CORS?<\/h2>\n<p><strong>CORS (Cross-Origin Resource Sharing) <\/strong>&#8212; \u0440\u0443\u0441\u0441\u043a\u043e\u0433\u043e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435 \u0438\u043c\u0435\u0435\u0442. \u0414\u043e\u0441\u043b\u043e\u0432\u043d\u043e &#171;\u043c\u0435\u0436\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432\u044b\u0439&#187; \u043e\u0431\u043c\u0435\u043d \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438.<\/p>\n<ul>\n<li>\n<p><strong>\u0426\u0435\u043b\u044c \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430<\/strong>:\u00a0\u0437\u0430\u0449\u0438\u0442\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u0442 \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u044b\u0445 \u0441\u0430\u0439\u0442\u043e\u0432 \u0437\u0430 \u0441\u0447\u0435\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u043d\u0435\u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0411\u0440\u0430\u0443\u0437\u0435\u0440<strong>\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 \u0440\u0435\u0441\u0443\u0440\u0441\u0430.<\/strong><\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 Access-Control.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438<\/strong> \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0434\u043e\u043c\u0435\u043d\u0430 \u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0411\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0438\u043b\u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u0447\u0442\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>: \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u0430\u0439\u0442 <a href=\"http:\/\/evil.com\" rel=\"noopener noreferrer nofollow\">evil.com<\/a>. \u0415\u0441\u043b\u0438 <a href=\"http:\/\/bank.com\" rel=\"noopener noreferrer nofollow\">bank.com<\/a> \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b CORS, JavaScript \u043d\u0430\u00a0<a href=\"http:\/\/evil.com\" rel=\"noopener noreferrer nofollow\">evil.com<\/a>\u00a0\u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u00a0\u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c\u00a0\u043e\u0442\u0432\u0435\u0442 \u043e\u0442\u00a0bank.com\/api\/account.<\/p>\n<p><strong>CORS \u043d\u0435 \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043e\u0442 \u043a\u0440\u043e\u0441\u0441-\u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 (CSRF-\u0430\u0442\u0430\u043a). <\/strong>\u0411\u0440\u0430\u0443\u0437\u0435\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430, \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u043e\u0442\u0432\u0435\u0442\u0430 \u0432 js \u043a\u043e\u0434.<\/p>\n<h2>3. \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 CORS<\/h2>\n<pre><code class=\"typescript\"># \u0420\u0430\u0437\u0440\u0435\u0448\u0451\u043d\u043d\u044b\u0435 \u0434\u043e\u043c\u0435\u043d\u044b (\u043e\u0434\u0438\u043d, \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u043b\u0438 *) Access-Control-Allow-Origin: https:\/\/frontend.com   # \u0420\u0430\u0437\u0440\u0435\u0448\u0451\u043d\u043d\u044b\u0435 HTTP-\u043c\u0435\u0442\u043e\u0434\u044b (\u0441\u043f\u0438\u0441\u043e\u043a \u0438\u043b\u0438 *) Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE  # \u0420\u0430\u0437\u0440\u0435\u0448\u0451\u043d\u043d\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438(\u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441) Access-Control-Allow-Headers: Authorization, Content-Type, X-Requested-With  # \u0420\u0430\u0437\u0440\u0435\u0448\u0451\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 (\u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441) Access-Control-Expose-Headers: Authorization, Content-Type, X-Requested-With  # \u0420\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u043a\u0443\u043a\/\u0442\u043e\u043a\u0435\u043d\u043e\u0432 Access-Control-Allow-Credentials: true  # \u041a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 600 \u0441\u0435\u043a (10 \u043c\u0438\u043d) Access-Control-Max-Age: 600<\/code><\/pre>\n<h2>4. \u041f\u0440\u0435\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u044b (Preflight-\u0437\u0430\u043f\u0440\u043e\u0441\u044b)<\/h2>\n<p>&#171;\u041f\u0440\u043e\u0441\u0442\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b&#187; (GET, POST, HEAD \u0431\u0435\u0437 \u0441\u043f\u0435\u0446. \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432) \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443.<\/p>\n<p>&#171;\u0421\u043b\u043e\u0436\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b&#187;, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 PUT, DELETE \u0438\u043b\u0438 \u0441 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c\u0438, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 &#171;\u043f\u0440\u0435\u0434\u0437\u0430\u043f\u0440\u043e\u0441&#187; (preflight request) \u043c\u0435\u0442\u043e\u0434\u043e\u043c OPTIONS. <\/p>\n<p>\u0421\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c, \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u044b \u043b\u0438 \u0442\u0430\u043a\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c GET \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c X-API-Key \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<p><code>http<\/code><\/p>\n<p><code>\/data HTTP\/1.1\u00a0<\/code><br \/><code>Origin: <\/code><a href=\"https:\/\/frontend.com\" rel=\"noopener noreferrer nofollow\"><code>https:\/\/frontend.com<\/code><\/a><br \/><code>Access-Control-Request-Headers: X-API-Key\u00a0 <\/code><\/p>\n<p>\u0421\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c:<\/p>\n<p><code>http<\/code><\/p>\n<p><code>HTTP\/1.1 204 OK\u00a0 <\/code><br \/><code>Access-Control-Allow-Origin: <\/code><a href=\"https:\/\/frontend.com\" rel=\"noopener noreferrer nofollow\"><code>https:\/\/frontend.com<\/code><\/a><code>\u00a0<\/code><br \/><code>Access-Control-Allow-Headers: X-API-Key\u00a0 <\/code><\/p>\n<p>\u0418 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441.<strong>\u00a0<\/strong><\/p>\n<h2>5. \u0427\u0442\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f &#171;\u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u043c\u0438&#187;?<\/h2>\n<p>\u041f\u0440\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 CORS \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u044b \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0443\u044f\u0441\u044c <strong>&#171;\u041f\u043e\u043b\u0438\u0442\u0438\u043a\u043e\u0439 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430&#187; \u0438\u043b\u0438<\/strong>\u00a0<strong>Same-Origin Policy (SOP)<\/strong>.<\/p>\n<p>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0440\u0435\u043c\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u043e\u0442\u043e\u043a\u043e\u043b (http\/https)<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043c\u0435\u043d (site.com\/api.site.com)<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0440\u0442 (:80\/:3000)<\/p>\n<\/li>\n<\/ol>\n<p>\u2705\u00a0<strong>\u041e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438:<\/strong><\/p>\n<p><a href=\"https:\/\/site.com\/page\" rel=\"noopener noreferrer nofollow\">https:\/\/site.com\/page<\/a>\u00a0\u0438\u00a0<a href=\"https:\/\/site.com\/about\" rel=\"noopener noreferrer nofollow\">https:\/\/site.com\/about<\/a> (\u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0438\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438)<\/p>\n<p> \u274c\u00a0<strong>\u0420\u0430\u0437\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438:<\/strong><\/p>\n<p><a href=\"http:\/\/site.com\" rel=\"noopener noreferrer nofollow\">http:\/\/site.com<\/a>\u00a0\u0438\u00a0<a href=\"https:\/\/site.com\" rel=\"noopener noreferrer nofollow\">https:\/\/site.com<\/a>\u00a0(\u0440\u0430\u0437\u043d\u044b\u0439 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b)<\/p>\n<p><a href=\"https:\/\/site.com\" rel=\"noopener noreferrer nofollow\">https:\/\/site.com<\/a>\u00a0\u0438\u00a0<a href=\"https:\/\/api.site.com\" rel=\"noopener noreferrer nofollow\">https:\/\/api.site.com<\/a>\u00a0(\u0440\u0430\u0437\u043d\u044b\u0439 \u0434\u043e\u043c\u0435\u043d)<\/p>\n<h2>6. \u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 CORS \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435?\u00a0<\/h2>\n<p>1.\u00a0<strong>\u041f\u0440\u043e\u0441\u0442\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b (GET\/POST \u0431\u0435\u0437 \u0441\u043f\u0435\u0446. \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432)<\/strong><\/p>\n<p>\u0411\u0440\u0430\u0443\u0437\u0435\u0440 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u0438\u0445, \u043d\u043e\u00a0<strong>\u043d\u0435 \u0434\u0430\u0441\u0442 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442<\/strong>, \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u0432 \u043e\u0442\u0432\u0435\u0442:<\/p>\n<p><code>http<\/code><\/p>\n<p><code>Access-Control-Allow-Origin: <\/code><a href=\"https:\/\/your-frontend.com\" rel=\"noopener noreferrer nofollow\"><code>https:\/\/your-frontend.com<\/code><\/a><\/p>\n<p>2.\u00a0<strong>\u0421\u043b\u043e\u0436\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b (PUT, DELETE, \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438)<\/strong><\/p>\n<p>\u0411\u0440\u0430\u0443\u0437\u0435\u0440 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u00a0<strong>\u043f\u0440\u0435\u0434\u0437\u0430\u043f\u0440\u043e\u0441 (OPTIONS)<\/strong>. \u0421\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c:<\/p>\n<p><code>http<\/code><\/p>\n<p><code>Access-Control-Allow-Origin: <\/code><a href=\"https:\/\/your-frontend.com\" rel=\"noopener noreferrer nofollow\"><code>https:\/\/your-frontend.com<\/code><\/a><br \/><code>Access-Control-Allow-Methods: POST, DELETE<\/code><br \/><code>Access-Control-Allow-Headers: Content-Type<\/code><\/p>\n<p>\u2192 \u0417\u0430\u0442\u0435\u043c \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<h2>7. \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f Express.js:<\/h2>\n<pre><code class=\"javascript\">\/\/ \u0420\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0441 frontend.com app.use((req, res, next) =&gt; { \u00a0 res.setHeader('Access-Control-Allow-Origin', 'https:\/\/frontend.com'); \u00a0 res.setHeader('Access-Control-Allow-Methods', 'GET, POST'); \u00a0 res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); \u00a0 next(); });<\/code><\/pre>\n<h2>8. \u041b\u0443\u0447\u0448\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 CORS<\/h2>\n<p>1.<strong>\u041d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u00a0*\u00a0\u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u044b\u0445      \u0434\u0430\u043d\u043d\u044b\u0445<\/strong><\/p>\n<p>\u0420\u0430\u0437\u0440\u0435\u0448\u0430\u0439\u0442\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0435 \u0434\u043e\u043c\u0435\u043d\u044b:<\/p>\n<p><code>Access-Control-Allow-Origin: <\/code><a href=\"https:\/\/your-frontend.com\" rel=\"noopener noreferrer nofollow\"><code>https:\/\/your-frontend.com<\/code><\/a><\/p>\n<p>2.<strong>\u0414\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0445 API \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0<\/strong>*<strong>:<\/strong><\/p>\n<p><code>Access-Control-Allow-Origin: *<\/code><\/p>\n<p>3.<strong>\u041a\u0443\u043a\u0438 = \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e!<\/strong><\/p>\n<p>\u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043a\u0443\u043a\u0438:<\/p>\n<p><code>http<\/code><\/p>\n<p><code>Access-Control-Allow-Credentials: true<\/code><br \/><code>Access-Control-Allow-Origin: <\/code><a href=\"https:\/\/frontend.com\" rel=\"noopener noreferrer nofollow\"><code>https:\/\/frontend.com<\/code><\/a><code> \/\/ \u041d\u0435\u043b\u044c\u0437\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c *<\/code><\/p>\n<p>4.<strong>\u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u044b:<\/strong><\/p>\n<p>\u0414\u043b\u044f\u00a0PUT,\u00a0DELETE\u00a0\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441\u00a0Authorization\u00a0\u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443\u00a0OPTIONS.<\/p>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u00a0Access-Control-Max-Age\u00a0\u0447\u0442\u043e\u0431\u044b \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440 (Nginx\/Apache) \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438,      \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 OPTIONS \u0431\u0435\u0437 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u00a0<\/p>\n<\/li>\n<\/ul>\n<h2>9. \u0427\u0430\u0441\u0442\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438<\/h2>\n<p>1.\u00a0\u00a0\u00a0\u00a0 <strong>\u0417\u0430\u0431\u044b\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435<\/strong>\u00a0\u2192 \u0411\u0440\u0430\u0443\u0437\u0435\u0440 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<p>2.\u00a0\u00a0\u00a0\u00a0 <strong>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u00a0<\/strong>*<strong>\u00a0\u0441 \u043a\u0443\u043a\u0430\u043c\u0438<\/strong>\u00a0\u2192 CORS \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<p>3.\u00a0\u00a0\u00a0\u00a0 <strong>\u041d\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 OPTIONS \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/strong>\u00a0\u2192 \u041f\u0440\u0435\u0434\u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f.<\/p>\n<h2>10. \u0418\u0442\u043e\u0433:<\/h2>\n<p>CORS \u2014 \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u043e\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u044b\u043c\u0438 \u0441\u0430\u0439\u0442\u0430\u043c\u0438. \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e <\/p>\n<p>\ud83d\udca1\u00a0<strong>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430:<\/strong>\u00a0\u041e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 \u0432\u043a\u043b\u0430\u0434\u043a\u0443 Network \u0432 DevTools. \u0418\u0449\u0438\u0442\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u044b\u00a0OPTIONS\u00a0\u0438\u00a0CORS headers\u00a0\u0432 \u043e\u0442\u0432\u0435\u0442\u0430\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<h2>11. \u0427\u0442\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c:<\/h2>\n<p><strong>W3C Cross-Origin Resource Sharing<br \/> <\/strong>\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f CORS (2014)<strong> <\/strong><a href=\"https:\/\/www.w3.org\/TR\/cors\/\" rel=\"noopener noreferrer nofollow\"><strong>https:\/\/www.w3.org\/TR\/cors\/<\/strong><\/a><\/p>\n<p><strong>MDN Web Docs: Cross-Origin Resource Sharing (CORS)<\/strong><br \/> <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Guides\/CORS\" rel=\"noopener noreferrer nofollow\">https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Guides\/CORS<\/a><\/p>\n<p><strong>\u0411\u0440\u0430\u0443\u0437\u0435\u0440\u043d\u0430\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c (Same-Origin Policy)<\/strong><br \/> \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430<br \/> <a href=\"https:\/\/web.dev\/articles\/same-origin-policy\" rel=\"noopener noreferrer nofollow\">https:\/\/web.dev\/articles\/same-origin-policy<\/a><\/p>\n<p><strong>CORS \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (Google Web Fundamentals)<\/strong><br \/> \u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u0434\u0430<br \/> <a href=\"https:\/\/web.dev\/articles\/cross-origin-resource-sharing\" rel=\"noopener noreferrer nofollow\">https:\/\/web.dev\/articles\/cross-origin-resource-sharing<\/a><\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u043b\u044e \u043d\u0430 \u043c\u0438\u0434\u043b+\/\u0441\u0435\u043d\u044c\u043e\u0440\u0430. \u0421\u043e\u0431\u0438\u0440\u0430\u044e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0434\u043b\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u043a \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044e \u0438 \u0434\u0435\u043b\u0430\u044e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u0425\u043e\u0447\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0435\u043c\u044b \u0442\u0440\u0443\u0434\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f &#8212; \u043f\u0438\u0448\u0438\u0442\u0435, \u043f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043c\u043e\u0433\u0443.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/935636\/\"> https:\/\/habr.com\/ru\/articles\/935636\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>\u0415\u0441\u043b\u0438 \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435 \u044d\u0442\u0443 \u043e\u0448\u0438\u0431\u043a\u0443 \u2014 \u0432\u044b \u043d\u0435 \u043e\u0434\u0438\u043d\u043e\u043a\u0438:<\/strong><\/p>\n<pre><code class=\"typescript\">Access to fetch at 'https:\/\/api.site.com' from origin 'http:\/\/localhost:3000'  has been blocked by CORS policy.<\/code><\/pre>\n<p><strong>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0438 \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u0447\u0438\u043d\u0438\u0442\u044c. \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 CORS, \u0438 \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d \u043d\u0443\u0436\u0435\u043d.<\/strong><\/p>\n<h2>1.\u00a0\u00a0\u00a0\u00a0 \u0417\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u0435\u043d CORS? \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c!\u00a0<\/h2>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0430\u0442\u0430\u043a\u0438:<\/strong><\/p>\n<ol>\n<li>\n<p>\u0412\u044b \u0432\u043e\u0448\u043b\u0438 \u043d\u0430\u00a0<a href=\"http:\/\/bank.com\" rel=\"noopener noreferrer nofollow\">bank.com<\/a>. \u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0441\u044c \u0432 \u043a\u0443\u043a\u0430\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0445\u043e\u0434\u0438\u0442\u0435 \u043d\u0430\u00a0<a href=\"http:\/\/evil.com\" rel=\"noopener noreferrer nofollow\">evil.com<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0430\u0439\u0442\u00a0<a href=\"http:\/\/evil.com\" rel=\"noopener noreferrer nofollow\">evil.com<\/a>\u00a0\u0442\u0430\u0439\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u00a0Get \/<strong>api\/account<\/strong> \u043d\u0430\u00a0<a href=\"http:\/\/bank.com\" rel=\"noopener noreferrer nofollow\">bank.com<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0411\u0440\u0430\u0443\u0437\u0435\u0440 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u0443\u043a\u0438 \u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0443 \u043d\u0430\u00a0<a href=\"http:\/\/bank.com\" rel=\"noopener noreferrer nofollow\">bank.com<\/a> \u2192 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0447\u0435\u0442\u0430 \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0434\u0435\u043d\u044c\u0433\u0438.<\/p>\n<\/li>\n<\/ol>\n<h2>2.\u00a0\u00a0\u00a0\u00a0 \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 CORS?<\/h2>\n<p><strong>CORS (Cross-Origin Resource Sharing) <\/strong>&#8212; \u0440\u0443\u0441\u0441\u043a\u043e\u0433\u043e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435 \u0438\u043c\u0435\u0435\u0442. \u0414\u043e\u0441\u043b\u043e\u0432\u043d\u043e &#171;\u043c\u0435\u0436\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432\u044b\u0439&#187; \u043e\u0431\u043c\u0435\u043d \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438.<\/p>\n<ul>\n<li>\n<p><strong>\u0426\u0435\u043b\u044c \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430<\/strong>:\u00a0\u0437\u0430\u0449\u0438\u0442\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u0442 \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u044b\u0445 \u0441\u0430\u0439\u0442\u043e\u0432 \u0437\u0430 \u0441\u0447\u0435\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u043d\u0435\u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0411\u0440\u0430\u0443\u0437\u0435\u0440<strong>\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 \u0440\u0435\u0441\u0443\u0440\u0441\u0430.<\/strong><\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 Access-Control.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438<\/strong> \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0434\u043e\u043c\u0435\u043d\u0430 \u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0411\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0438\u043b\u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u0447\u0442\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>: \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u0430\u0439\u0442 <a href=\"http:\/\/evil.com\" rel=\"noopener noreferrer nofollow\">evil.com<\/a>. \u0415\u0441\u043b\u0438 <a href=\"http:\/\/bank.com\" rel=\"noopener noreferrer nofollow\">bank.com<\/a> \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b CORS, JavaScript \u043d\u0430\u00a0<a href=\"http:\/\/evil.com\" rel=\"noopener noreferrer nofollow\">evil.com<\/a>\u00a0\u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u00a0\u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c\u00a0\u043e\u0442\u0432\u0435\u0442 \u043e\u0442\u00a0bank.com\/api\/account.<\/p>\n<p><strong>CORS \u043d\u0435 \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043e\u0442 \u043a\u0440\u043e\u0441\u0441-\u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 (CSRF-\u0430\u0442\u0430\u043a). <\/strong>\u0411\u0440\u0430\u0443\u0437\u0435\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430, \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u043e\u0442\u0432\u0435\u0442\u0430 \u0432 js \u043a\u043e\u0434.<\/p>\n<h2>3. \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 CORS<\/h2>\n<pre><code class=\"typescript\"># \u0420\u0430\u0437\u0440\u0435\u0448\u0451\u043d\u043d\u044b\u0435 \u0434\u043e\u043c\u0435\u043d\u044b (\u043e\u0434\u0438\u043d, \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u043b\u0438 *) Access-Control-Allow-Origin: https:\/\/frontend.com   # \u0420\u0430\u0437\u0440\u0435\u0448\u0451\u043d\u043d\u044b\u0435 HTTP-\u043c\u0435\u0442\u043e\u0434\u044b (\u0441\u043f\u0438\u0441\u043e\u043a \u0438\u043b\u0438 *) Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE  # \u0420\u0430\u0437\u0440\u0435\u0448\u0451\u043d\u043d\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438(\u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441) Access-Control-Allow-Headers: Authorization, Content-Type, X-Requested-With  # \u0420\u0430\u0437\u0440\u0435\u0448\u0451\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 (\u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441) Access-Control-Expose-Headers: Authorization, Content-Type, X-Requested-With  # \u0420\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u043a\u0443\u043a\/\u0442\u043e\u043a\u0435\u043d\u043e\u0432 Access-Control-Allow-Credentials: true  # \u041a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 600 \u0441\u0435\u043a (10 \u043c\u0438\u043d) Access-Control-Max-Age: 600<\/code><\/pre>\n<h2>4. \u041f\u0440\u0435\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u044b (Preflight-\u0437\u0430\u043f\u0440\u043e\u0441\u044b)<\/h2>\n<p>&#171;\u041f\u0440\u043e\u0441\u0442\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b&#187; (GET, POST, HEAD \u0431\u0435\u0437 \u0441\u043f\u0435\u0446. \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432) \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443.<\/p>\n<p>&#171;\u0421\u043b\u043e\u0436\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b&#187;, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 PUT, DELETE \u0438\u043b\u0438 \u0441 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c\u0438, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 &#171;\u043f\u0440\u0435\u0434\u0437\u0430\u043f\u0440\u043e\u0441&#187; (preflight request) \u043c\u0435\u0442\u043e\u0434\u043e\u043c OPTIONS. <\/p>\n<p>\u0421\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c, \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u044b \u043b\u0438 \u0442\u0430\u043a\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c GET \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c X-API-Key \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<p><code>http<\/code><\/p>\n<p><code>\/data HTTP\/1.1\u00a0<\/code><br \/><code>Origin: <\/code><a href=\"https:\/\/frontend.com\" rel=\"noopener noreferrer nofollow\"><code>https:\/\/frontend.com<\/code><\/a><br \/><code>Access-Control-Request-Headers: X-API-Key\u00a0 <\/code><\/p>\n<p>\u0421\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c:<\/p>\n<p><code>http<\/code><\/p>\n<p><code>HTTP\/1.1 204 OK\u00a0 <\/code><br \/><code>Access-Control-Allow-Origin: <\/code><a href=\"https:\/\/frontend.com\" rel=\"noopener noreferrer nofollow\"><code>https:\/\/frontend.com<\/code><\/a><code>\u00a0<\/code><br \/><code>Access-Control-Allow-Headers: X-API-Key\u00a0 <\/code><\/p>\n<p>\u0418 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441.<strong>\u00a0<\/strong><\/p>\n<h2>5. \u0427\u0442\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f &#171;\u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u043c\u0438&#187;?<\/h2>\n<p>\u041f\u0440\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 CORS \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u044b \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0443\u044f\u0441\u044c <strong>&#171;\u041f\u043e\u043b\u0438\u0442\u0438\u043a\u043e\u0439 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430&#187; \u0438\u043b\u0438<\/strong>\u00a0<strong>Same-Origin Policy (SOP)<\/strong>.<\/p>\n<p>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0440\u0435\u043c\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u043e\u0442\u043e\u043a\u043e\u043b (http\/https)<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043c\u0435\u043d (site.com\/api.site.com)<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0440\u0442 (:80\/:3000)<\/p>\n<\/li>\n<\/ol>\n<p>\u2705\u00a0<strong>\u041e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438:<\/strong><\/p>\n<p><a href=\"https:\/\/site.com\/page\" rel=\"noopener noreferrer nofollow\">https:\/\/site.com\/page<\/a>\u00a0\u0438\u00a0<a href=\"https:\/\/site.com\/about\" rel=\"noopener noreferrer nofollow\">https:\/\/site.com\/about<\/a> (\u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0438\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438)<\/p>\n<p> \u274c\u00a0<strong>\u0420\u0430\u0437\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438:<\/strong><\/p>\n<p><a href=\"http:\/\/site.com\" rel=\"noopener noreferrer nofollow\">http:\/\/site.com<\/a>\u00a0\u0438\u00a0<a href=\"https:\/\/site.com\" rel=\"noopener noreferrer nofollow\">https:\/\/site.com<\/a>\u00a0(\u0440\u0430\u0437\u043d\u044b\u0439 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b)<\/p>\n<p><a href=\"https:\/\/site.com\" rel=\"noopener noreferrer nofollow\">https:\/\/site.com<\/a>\u00a0\u0438\u00a0<a href=\"https:\/\/api.site.com\" rel=\"noopener noreferrer nofollow\">https:\/\/api.site.com<\/a>\u00a0(\u0440\u0430\u0437\u043d\u044b\u0439 \u0434\u043e\u043c\u0435\u043d)<\/p>\n<h2>6. \u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 CORS \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435?\u00a0<\/h2>\n<p>1.\u00a0<strong>\u041f\u0440\u043e\u0441\u0442\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b (GET\/POST \u0431\u0435\u0437 \u0441\u043f\u0435\u0446. \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432)<\/strong><\/p>\n<p>\u0411\u0440\u0430\u0443\u0437\u0435\u0440 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u0438\u0445, \u043d\u043e\u00a0<strong>\u043d\u0435 \u0434\u0430\u0441\u0442 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442<\/strong>, \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u0432 \u043e\u0442\u0432\u0435\u0442:<\/p>\n<p><code>http<\/code><\/p>\n<p><code>Access-Control-Allow-Origin: <\/code><a href=\"https:\/\/your-frontend.com\" rel=\"noopener noreferrer nofollow\"><code>https:\/\/your-frontend.com<\/code><\/a><\/p>\n<p>2.\u00a0<strong>\u0421\u043b\u043e\u0436\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b (PUT, DELETE, \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438)<\/strong><\/p>\n<p>\u0411\u0440\u0430\u0443\u0437\u0435\u0440 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u00a0<strong>\u043f\u0440\u0435\u0434\u0437\u0430\u043f\u0440\u043e\u0441 (OPTIONS)<\/strong>. \u0421\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c:<\/p>\n<p><code>http<\/code><\/p>\n<p><code>Access-Control-Allow-Origin: <\/code><a href=\"https:\/\/your-frontend.com\" rel=\"noopener noreferrer nofollow\"><code>https:\/\/your-frontend.com<\/code><\/a><br \/><code>Access-Control-Allow-Methods: POST, DELETE<\/code><br \/><code>Access-Control-Allow-Headers: Content-Type<\/code><\/p>\n<p>\u2192 \u0417\u0430\u0442\u0435\u043c \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<h2>7. \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f Express.js:<\/h2>\n<pre><code class=\"javascript\">\/\/ \u0420\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0441 frontend.com app.use((req, res, next) =&gt; { \u00a0 res.setHeader('Access-Control-Allow-Origin', 'https:\/\/frontend.com'); \u00a0 res.setHeader('Access-Control-Allow-Methods', 'GET, POST'); \u00a0 res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); \u00a0 next(); });<\/code><\/pre>\n<h2>8. \u041b\u0443\u0447\u0448\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 CORS<\/h2>\n<p>1.<strong>\u041d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u00a0*\u00a0\u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u044b\u0445      \u0434\u0430\u043d\u043d\u044b\u0445<\/strong><\/p>\n<p>\u0420\u0430\u0437\u0440\u0435\u0448\u0430\u0439\u0442\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0435 \u0434\u043e\u043c\u0435\u043d\u044b:<\/p>\n<p><code>Access-Control-Allow-Origin: <\/code><a href=\"https:\/\/your-frontend.com\" rel=\"noopener noreferrer nofollow\"><code>https:\/\/your-frontend.com<\/code><\/a><\/p>\n<p>2.<strong>\u0414\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0445 API \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0<\/strong>*<strong>:<\/strong><\/p>\n<p><code>Access-Control-Allow-Origin: *<\/code><\/p>\n<p>3.<strong>\u041a\u0443\u043a\u0438 = \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e!<\/strong><\/p>\n<p>\u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043a\u0443\u043a\u0438:<\/p>\n<p><code>http<\/code><\/p>\n<p><code>Access-Control-Allow-Credentials: true<\/code><br \/><code>Access-Control-Allow-Origin: <\/code><a href=\"https:\/\/frontend.com\" rel=\"noopener noreferrer nofollow\"><code>https:\/\/frontend.com<\/code><\/a><code> \/\/ \u041d\u0435\u043b\u044c\u0437\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c *<\/code><\/p>\n<p>4.<strong>\u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u044b:<\/strong><\/p>\n<p>\u0414\u043b\u044f\u00a0PUT,\u00a0DELETE\u00a0\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441\u00a0Authorization\u00a0\u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443\u00a0OPTIONS.<\/p>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u00a0Access-Control-Max-Age\u00a0\u0447\u0442\u043e\u0431\u044b \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440 (Nginx\/Apache) \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438,      \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 OPTIONS \u0431\u0435\u0437 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u00a0<\/p>\n<\/li>\n<\/ul>\n<h2>9. \u0427\u0430\u0441\u0442\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438<\/h2>\n<p>1.\u00a0\u00a0\u00a0\u00a0 <strong>\u0417\u0430\u0431\u044b\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435<\/strong>\u00a0\u2192 \u0411\u0440\u0430\u0443\u0437\u0435\u0440 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<p>2.\u00a0\u00a0\u00a0\u00a0 <strong>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u00a0<\/strong>*<strong>\u00a0\u0441 \u043a\u0443\u043a\u0430\u043c\u0438<\/strong>\u00a0\u2192 CORS \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<p>3.\u00a0\u00a0\u00a0\u00a0 <strong>\u041d\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 OPTIONS \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/strong>\u00a0\u2192 \u041f\u0440\u0435\u0434\u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f.<\/p>\n<h2>10. \u0418\u0442\u043e\u0433:<\/h2>\n<p>CORS \u2014 \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u043e\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u044b\u043c\u0438 \u0441\u0430\u0439\u0442\u0430\u043c\u0438. \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e <\/p>\n<p>\ud83d\udca1\u00a0<strong>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430:<\/strong>\u00a0\u041e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 \u0432\u043a\u043b\u0430\u0434\u043a\u0443 Network \u0432 DevTools. \u0418\u0449\u0438\u0442\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u044b\u00a0OPTIONS\u00a0\u0438\u00a0CORS headers\u00a0\u0432 \u043e\u0442\u0432\u0435\u0442\u0430\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<h2>11. \u0427\u0442\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c:<\/h2>\n<p><strong>W3C Cross-Origin Resource Sharing<br \/> <\/strong>\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f CORS (2014)<strong> <\/strong><a href=\"https:\/\/www.w3.org\/TR\/cors\/\" rel=\"noopener noreferrer nofollow\"><strong>https:\/\/www.w3.org\/TR\/cors\/<\/strong><\/a><\/p>\n<p><strong>MDN Web Docs: Cross-Origin Resource Sharing (CORS)<\/strong><br \/> <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Guides\/CORS\" rel=\"noopener noreferrer nofollow\">https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Guides\/CORS<\/a><\/p>\n<p><strong>\u0411\u0440\u0430\u0443\u0437\u0435\u0440\u043d\u0430\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c (Same-Origin Policy)<\/strong><br \/> \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430<br \/> <a href=\"https:\/\/web.dev\/articles\/same-origin-policy\" rel=\"noopener noreferrer nofollow\">https:\/\/web.dev\/articles\/same-origin-policy<\/a><\/p>\n<p><strong>CORS \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (Google Web Fundamentals)<\/strong><br \/> \u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u0434\u0430<br \/> <a href=\"https:\/\/web.dev\/articles\/cross-origin-resource-sharing\" rel=\"noopener noreferrer nofollow\">https:\/\/web.dev\/articles\/cross-origin-resource-sharing<\/a><\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u043b\u044e \u043d\u0430 \u043c\u0438\u0434\u043b+\/\u0441\u0435\u043d\u044c\u043e\u0440\u0430. \u0421\u043e\u0431\u0438\u0440\u0430\u044e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0434\u043b\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u043a \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044e \u0438 \u0434\u0435\u043b\u0430\u044e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u0425\u043e\u0447\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0435\u043c\u044b \u0442\u0440\u0443\u0434\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f &#8212; \u043f\u0438\u0448\u0438\u0442\u0435, \u043f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043c\u043e\u0433\u0443.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/935636\/\"> https:\/\/habr.com\/ru\/articles\/935636\/<\/a><br \/><\/br><\/br><\/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-470145","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/470145","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=470145"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/470145\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=470145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=470145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=470145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}