Same-Origin Policy ã¨ã¯ä½ãªã®ãã
ã¡ãã£ã¨åã£ãWebã¢ããªã±ã¼ã·ã§ã³ãä½æãã¦ãããããããã¯Webã®ã»ãã¥ãªãã£ã«é¢ãã£ã¦ãã人ãªãã°ãSame-Origin Policyã(SOP)ã¨ããè¨èãä¸åº¦ã¯èãããã¨ãããã¨æãã¾ããæ¥æ¬èªã§ã¯ãåä¸çæå
ããªã·ã¼ããããã¯ãåä¸çææºããªã·ã¼ããªã©ã¨è¨³ããããã¨ãããã¾ãããå人çã«ã¯ããªãªã¸ã³ãã¯åºæã®æ¦å¿µã表ãèªãªã®ã§ä¸æã«è¨³ãããåä¸ãªãªã¸ã³ããªã·ã¼ãã¨æ¸ãã¦ããã®ã好ãã§ãã
ãã¦ããã®ããªãªã¸ã³ãã¨ã¯ä½ãªã®ãã¨ãã話ã§ãããããã¯ãRFC 6454 - The Web Origin Conceptãã§å®ãããã¦ããã端çã«è¨ãã¨ãã¹ãã¼ã ããã¹ãããã¼ããã®çµã¿åããããªãªã¸ã³ã¨å®ããããããåããã®ã¯åä¸ã®ãªãªã¸ã³ã¨ãã¦åãä¿è·ç¯å²ã®ãªã½ã¼ã¹ã¨ãã¦åãæ±ãã¨ãããã¨ã§ãã
ä¾ãã°ãhttp://example.jp/fooã¨http://example.jp:80/barã¯ããããåä¸ã®ã¹ãã¼ã (http)ããã¹ã(example.jp)ããã¼ã(80)ãæã¤ãããåä¸ã®ãªãªã¸ã³ã§ããã¨å¤æããã¾ããä¸æ¹ãhttps://example.jp/fooã¨http://example.jp/fooã¯ã©ã¡ããåããã¹ããæã¡ã¾ãããã¹ãã¼ã ãããããhttpsã¨httpã§ãããããç°ãªããªãªã¸ã³ã®ãªã½ã¼ã¹ã§ããã¨å¤æããã¾ããdata:ã¹ãã¼ã ã¯ããããç¬ç«ãããªãªã¸ã³ãæã¤ãã®ã¨ãã¦åãæ±ãããã¾ãfile:ã¹ãã¼ã ã«é¢ãã¦ã¯å®è£
ä¾åã¨ãããã¨ã«ãªã£ã¦ãã¾ãã2ã¤ã®ãªãªã¸ã³ãåä¸ã§ãªãå ´åãããªãã¡ç°ãªããªãªã¸ã³ããã¯ãã¹ãªãªã¸ã³ãã¨è¨ãã¾ãã
RFC6454ã§ã¯ãç¾å¨ã®ããã¥ã¡ã³ãã®ãªãªã¸ã³ãæ£è¦åãã¦è¡¨ç¾ããæ¹æ³ãå®ãããã¦ãããä¾ãã°http://example.jp:80/foo/bar/ã¨ãããªã½ã¼ã¹ã§ããã°ãªãªã¸ã³ã¯æ£è¦åããã¨http://example.jpã¨ãªãã¾ããæè¿ã®WebKitç³»ã®ãã©ã¦ã¶ã§ã¯ã表示ãã¦ããããã¥ã¡ã³ãã®ãªãªã¸ã³ã示ã location.origin ã¨ããããããã£ãå®è£
ããã¦ãã¾ãã
ãªãªã¸ã³ã«ä¾åãã¦åä½ãå¶ç´ããããã®ã¨ãã¦ã¯ã以ä¸ã®ãããªãã®ãããã¾ãã
- XMLHttpRequest
- åä¸ãªãªã¸ã³ã§ã¯ç¡æ¡ä»¶ã«ã¬ã¹ãã³ã¹ãèªããã¨ãã§ãã¾ãããã¯ãã¹ãªãªã¸ã³ã§ã¯è¨±å¯ãããå ´åã«ããã¬ã¹ãã³ã¹ã«ã¢ã¯ã»ã¹ãããã¨ã¯ã§ãã¾ããã
- Canvas
- Canvasã«è¡¨ç¤ºãããç»åã¯ãåä¸ãªãªã¸ã³ã§ããã°ç»åãã¼ã¿ã«JavaScriptããã¢ã¯ã»ã¹ãããã¨ãã§ãã¾ãããã¯ãã¹ãªãªã¸ã³ã®å ´åã«ã¯è¨±å¯ãããå ´åã«ããã¢ã¯ã»ã¹ã§ãã¾ããã
- Web Storage
- ãã¼ã¿ã®ä¿åãããåä½ã¯ãªãªã¸ã³ã«åºã¥ãã¾ããã¯ãã¹ãªãªã¸ã³ã§ã®ãã¼ã¿ã®èªã¿æ¸ãã¯ã§ãã¾ããã
- X-Frame-Options
- SAMEORIGINã®ãããªæå®ãããå ´åã«ã¯ããªãªã¸ã³ãè¶ ãã¦ãã¬ã¼ã å ã«ã³ã³ãã³ããå«ãããã¨ã¯ã§ãã¾ããã
ããã以å¤ã«ãWebä¸ã®æ§ã
ãªæåã«ã¤ãã¦ã対象ãåä¸ãªãªã¸ã³ã®å ´åã«ã¯å¶ç´ãªãã«ãªã½ã¼ã¹ã®èªã¿æ¸ããå¯è½ã¨ãªãã®ã«å¯¾ããã¯ãã¹ãªãªã¸ã³ã®å ´åã«ã¯ååã¨ãã¦ãªã½ã¼ã¹ã®èªã¿æ¸ããç¦æ¢ã«ãªããã¨ããåä¸ãªãªã¸ã³ããªã·ã¼ãã¨è¨ãã¾ãã
ä¸æ¹ããªãªã¸ã³ä»¥å¤ããã¼ã¹ã«åä½ã®å¶ç´ã«å®ãã¦ãããã®ã¨ãã¦ã¯ä»¥ä¸ã®ãããªãã®ãããã¾ãã
- Cookie
- Cookieã¯pathãdomainæå®ãå¯è½ã§ãããã¾ãããã©ã«ãã§ã¯httpã¨httpsã§å ±æããã¾ãã
- HTTPèªè¨¼
- HTTPèªè¨¼ã¯pathåãå ã«èªè¨¼æ å ±ãéä¿¡ãããªã©ããªãªã¸ã³ã«åºã¥ããªãåä½ã¨ãªãã¾ãã
- document.domain
- JavaScriptã§document.domainãæ¸ãæãããã¨ã«ãããã¹ããè¶ ãã¦innerHTMLãªã©ã®èªã¿æ¸ããå¯è½ã«ãªãã¾ãã
XMLHttpRequestãCanvasãªã©ã®ãªãªã¸ã³ã«ããå¶ç´ãåããæ©æ§ã«ããã¦ãã¯ãã¹ãªãªã¸ã³ã§ã®ãªã½ã¼ã¹ã§ã¢ã¯ã»ã¹ããæ¹æ³ã«ã¤ãã¦ã¯ãCross-Origin Resource Sharing(CORS)ãã«ã¼ã«ã¨ãã¦å®ãããã¦ãã¾ããCORSã«åºã¥ãã¦ãªã¯ã¨ã¹ããã¬ã¹ãã³ã¹ãçºè¡ãããã¨ã«ãããXMLHttpRequestãCanvasã«ããã¦ã¯ãã¹ãªãªã¸ã³ã§ãªã½ã¼ã¹ã«ã¢ã¯ã»ã¹ãããã¨ãå¯è½ã«ãªãã¾ããCORSã«ã¤ãã¦ã¯ããHTTP access control | MDNããæ¥æ¬èªã§ããã¾ã¨ã¾ã£ã¦ãã¾ãã®ã§åç §ããã¨ããã¨æãã¾ãã
ã¾ã£ããã®ä½è«ã«ãªãã¾ããããã¯ãã¹ãµã¤ãã¹ã¯ãªããã£ã³ã°ãã¨ããæ»æææ³ã®ååã«ã¤ãã¦ãä½ããã¯ãã¹ãµã¤ãããªã®ãåãããªããã¨ãã声ãããèãã¾ãããããã§ããããµã¤ããã¯ç´ç²ãªæå³ã§ã®ãµã¤ãã§ã¯ãªããªãªã¸ã³ã示ãã¦ããã®ã§ãããã¯ãã¹ãµã¤ãã¹ã¯ãªããã£ã³ã°ã¯ãªãªã¸ã³ãè¶ ãã¦ã¹ã¯ãªãããæ³¨å ¥ããæ»æã ã¨èããã¨ãããã¨ãã£ããæ¥ããããªæ°ããã¾ãã