SOPの話15. JavaScriptからcanvasへの
アクセス
var img = new Image();
img.src = ‘http://example.com/secretimg.png’;
img.onload = function() {
var canvas = $('canvas')[0];
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
var data = ctx.createImageData(50, 50);
}
16. file:// プロトコル
• Chrome, Safari
• XHR禁止
• Firefox
• サブディレクトリ許可
• Downloadsディレクトリ危ない
• IE7~
• JavaScript実行に警告
• IE6
• なにそれおいしいの
19. Flash + crossdomain.xml
• サーバに、アクセス許可ポリシを置いておく
• Flashはそれがあるサーバにはアクセスして良
い
• まさか、深く考えずに全許可とかする馬鹿な
Webアプリ開発者はいないだろう
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*"/>
</cross-domain-policy>
21. CORS
• Cross Origin Resource Sharing
• XMLHttpRequest Level 2
• ブラウザは試しにアクセスしてみる
• サーバがAccess-Control-Allow-Originヘッダなどを返
す
• ブラウザは、ヘッダを見てアクセスOKなら処理続
行
• ブラウザは、ヘッダを見てアクセスNGなら処理中
止
• サーバ、クライアント両方対応が必要
• Opera, IEは非対応
31. Cookie: domain
(http://foo.example.com/)
Set-Cookie: SessionID=12345; domain=??????
設定する値
有効範囲
(未指定)
foo.example.com
← いちばん限定される
bar.foo.example.com Cookieは設定されない
hoge.example.com
Cookieは設定されない
foo.example.com
*.foo.example.com
← 未指定より広くなる
example.com
*.example.com
← いちばん広くなる
google.com
Cookieは設定されない
.com
Cookieは設定されない
← トップレベルは設定不可
指定するとセキュリティ下がりやすい。必要ないなら指定しない。
32. Cookie: domain
(http://foo.example.com/)
Set-Cookie: SessionID=12345; domain=??????
設定する値
有効範囲
(未指定)
foo.example.com
← いちばん限定される
bar.foo.example.com Cookieは設定されない
hoge.example.com
Cookieは設定されない
foo.example.com
*.foo.example.com
← 未指定より広くなる
example.com
*.example.com
← いちばん広くなる
google.com
Cookieは設定されない
.com
Cookieは設定されない
← トップレベルは設定不可
これはどうやって判別してるのか?
33. Cookie: domain
Only hosts within the specified domain can set a
cookie for a domain and domains must have at least
two (2) or three (3) periods in them to prevent
domains of the form: ".com", ".edu", and "va.us".
Any domain that fails within one of the seven special
top level domains listed below only require two
periods. Any other domain requires at least three.
The seven special top level domains are:
"COM", "EDU", "NET", "ORG", "GOV", "MIL", and
"INT".
http://curl.haxx.se/rfc/cookie_spec.html