{"id":13879,"date":"2021-07-31T15:46:20","date_gmt":"2021-07-31T06:46:20","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=13879"},"modified":"2023-05-28T08:00:31","modified_gmt":"2023-05-27T23:00:31","slug":"%e3%80%90web%e3%80%91%e3%80%8ccors%e3%80%8d%e3%82%92%e4%bd%bf%e3%82%8f%e3%81%aa%e3%81%84sop%e3%81%ae%e7%b7%a9%e5%92%8c%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=13879","title":{"rendered":"\u3010Web\u3011\u300cCORS\u300d\u3092\u4f7f\u308f\u306a\u3044SOP\u306e\u7de9\u548c\u65b9\u6cd5"},"content":{"rendered":"<h2>\u305d\u3082\u305d\u3082SOP\u3068\u306f\uff1f<\/h2>\n<p>\u300cSame Origin Policy\u300d\u306e\u7565\u3067\u300cSame-Origin\u300d\u3067\u306f\u30a2\u30af\u30bb\u30b9\u3067\u304d\u3066\u3082\u3001\u300cCross-Origin\u300d\u3067\u306f\u30a2\u30af\u30bb\u30b9\u5236\u9650\u304c\u3042\u308b\u3068\u3044\u3046\u4ed5\u7d44\u307f\u3067\u3059\u3002\u8a73\u3057\u304f\u306f\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3067\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"JYJhcJDyPx\"><p><a href=\"http:\/\/www.code-magagine.com\/?p=13870\">\u3010Web\u3011\u540c\u4e00\u751f\u6210\u5143\u30dd\u30ea\u30b7\u30fc(SOP)\u306b\u3064\u3044\u3066<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/www.code-magagine.com\/?p=13870&#038;embed=true#?secret=JYJhcJDyPx\" data-secret=\"JYJhcJDyPx\" width=\"500\" height=\"282\" title=\"&#8220;\u3010Web\u3011\u540c\u4e00\u751f\u6210\u5143\u30dd\u30ea\u30b7\u30fc(SOP)\u306b\u3064\u3044\u3066&#8221; &#8212; \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30de\u30ac\u30b8\u30f3\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>SOP\u56de\u907f\u306fCORS(Cross-Origin Resource Sharing)\u3092\u4f7f\u3046\u306e\u304c\u4e00\u822c\u7684\u306b\u306a\u3063\u3066\u304d\u3066\u3044\u307e\u3059\u304c\u3001\u6280\u8853\u7684\u306a\u5236\u7d04\u304c\u3042\u308b\u305f\u3081\u306bCORS\u304c\u3069\u3046\u3057\u3066\u3082\u4f7f\u3048\u306a\u3044\u5834\u9762\u306f\u3042\u308a\u307e\u3059\u3002\u305d\u306e\u5834\u5408\u306f\u3044\u304f\u3064\u304b\u306e\u56de\u907f\u7b56\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2>JSONP(JSON with Padding)\u3092\u7528\u3044\u305f\u65b9\u6cd5<\/h2>\n<p>\u4e88\u3081\u7528\u610f\u3057\u305f\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u306e\u540d\u524d\u3092Cross-Origin\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u306b\u4f1d\u3048\u308b\u3068\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3067\u306f\u5171\u6709\u3057\u305f\u3044\u30ea\u30bd\u30fc\u30b9\u3092\u5f15\u6570\u3068\u3057\u3066\u305d\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u304c\u547c\u3073\u51fa\u3055\u308c\u308b\u3068\u3044\u3046\u3082\u306e\u3002<\/p>\n<h3>\u4ed5\u7d44\u307f<\/h3>\n<p>\u30af\u30ed\u30b9\u30aa\u30ea\u30b8\u30f3\u3067\u3082\u3001\u57cb\u3081\u8fbc\u307f(JavaScript\u306e\u30ed\u30fc\u30c9)\u3060\u3051\u306f\u8a31\u53ef\u3055\u308c\u3066\u3044\u308b\u3068\u3044\u3046\u6027\u8cea\u3092\u5229\u7528\u3057\u3066\u5024\u3092\u53d6\u308a\u51fa\u3059\u624b\u6cd5\u3067\u3059\u3002<\/p>\n<h3>JSONP\u306e\u30c7\u30e1\u30ea\u30c3\u30c8<\/h3>\n<p>\u4ee5\u4e0b\u306e\u30c7\u30e1\u30ea\u30c3\u30c8\u304c\u3042\u308b\u306e\u3067\u3067\u304d\u308b\u3060\u3051JSONP\u3092\u4f7f\u3046\u306e\u306f\u907f\u3051\u3066\u306a\u308b\u3079\u304fCORS\u3092\u7528\u3044\u308b\u3079\u304d\u3002<\/p>\n<ul>\n<li>\u653b\u6483\u8005\u306b\u3088\u308a\u3001CSP(Content Security Policy)\u306e\u8fc2\u56de\u306b\u4f7f\u308f\u308c\u308b\u3053\u3068\u3082\u3042\u308b\u3002<\/li>\n<li>JavaScript\u306e\u4ee3\u308f\u308a\u306bHTML\u304c\u8fd4\u5374\u3055\u308c\u308b\u30bf\u30a4\u30d7\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u306e\u5834\u5408\u306b\u306f\u3001SOME(Same Origin Method Execution)\u3068\u547c\u3070\u308c\u308b\u653b\u6483\u306b\u4f7f\u308f\u308c\u308b\u3053\u3068\u3082\u3042\u308b\u3002<\/li>\n<\/ul>\n<h2>XMLHttpRequest2<\/h2>\n<p>\u30af\u30ed\u30b9\u30c9\u30e1\u30a4\u30f3\u5236\u7d04\u3092\u56de\u907f\u3067\u304d\u308b\u3002<\/p>\n<p>\u30b5\u30fc\u30d0\u30fc\u5074\u3067\u300cAccess-Control-Allow-Origin\u300d\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n<h2>postMessage\u3092\u7528\u3044\u305f\u65b9\u6cd5<\/h2>\n<p>Web\u30d6\u30e9\u30a6\u30b6\u304c\u63d0\u4f9b\u3057\u3066\u3044\u308bJavaScript\u306e\u30e1\u30bd\u30c3\u30c9postMessage\u3092\u7528\u3044\u305f\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<h3>postMessage\u3068\u306f\uff1f<\/h3>\n<p>\u5f53\u8a72\u30a6\u30a4\u30f3\u30c9\u30a6\u306b\u5bfe\u3057\u3066\u30c7\u30fc\u30bf\u3092\u9001\u4fe1\u3059\u308b\u305f\u3081\u306e\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">const w = window.open(\"http:\/\/xxx.com\");\r\nw.postMessage(\"\u9001\u4fe1\u3057\u305f\u3044\u30e1\u30c3\u30bb\u30fc\u30b8\",\u9001\u4fe1\u5148\u30a6\u30a4\u30f3\u30c9\u30a6\u306eOrigin)<\/pre>\n<h2>document.domain\u306b\u3088\u308b\u65b9\u6cd5<\/h2>\n<h3>document.domain\u3068\u306f\uff1f<\/h3>\n<p>Web\u30da\u30fc\u30b8\u306eURL\u4e2d\u306e\u30c9\u30e1\u30a4\u30f3\u540d\u304b\u3001\u305d\u308c\u3088\u308a\u4e0a\u4f4d\u306e\u30c9\u30e1\u30a4\u30f3\u540d\u3092\u5024\u3068\u3057\u3066\u53d6\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u30d7\u30ed\u30d1\u30c6\u30a3\u3067\u3059\u30022\u3064\u306eWeb\u30da\u30fc\u30b8\u304c\u660e\u793a\u7684\u306b\u540c\u3058\u5024\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u308b\u6642\u306f\u3001Cross-Origin\u306eDOM\u30a2\u30af\u30bb\u30b9\u304c\u8a31\u53ef\u3055\u308c\u308b\u3002<\/p>\n<h3>\u6ce8\u610f\u70b9<\/h3>\n<p>Cross-Origin\u306aDOM\u30a2\u30af\u30bb\u30b9\u3078\u306e\u5236\u9650\u306e\u7de9\u548c\u306b\u3057\u304b\u5229\u7528\u3067\u304d\u306a\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u305d\u3082\u305d\u3082SOP\u3068\u306f\uff1f \u300cSame Origin Policy\u300d\u306e\u7565\u3067\u300cSame-Origin\u300d\u3067\u306f\u30a2\u30af\u30bb\u30b9\u3067\u304d\u3066\u3082\u3001\u300cCross-Origin\u300d\u3067\u306f\u30a2\u30af\u30bb\u30b9\u5236\u9650\u304c\u3042\u308b\u3068\u3044\u3046\u4ed5\u7d44\u307f\u3067\u3059\u3002\u8a73\u3057\u304f\u306f\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3067\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002 [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[122],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13879"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13879"}],"version-history":[{"count":7,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13879\/revisions"}],"predecessor-version":[{"id":20679,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13879\/revisions\/20679"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13879"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}