LoginSignup
15
5

More than 5 years have passed since last update.

ITPのBANを早速試しました

Last updated at Posted at 2017-12-14

この記事は MicroAd Advent Calendar 2017 の15日目の記事です。
2017/12/15 といえば、スター・ウォーズ エピソード8/最後のジェダイ の公開日です。ファンの皆さん、お楽しみですね。

はじめに

Safari11 がリリースしてから3ヶ月立てました、ネット広告業界が大騒いだ ITP 機能はご存知ですよね。
本記事はITP機能に 3rd-party cookie が BAN される方法を紹介します。

テスト環境

  • OS: macOS High Sierra
  • Browser: Safari 11 ITP有効 (環境設定 -> プライバシー -> サイト越えトラッキングを防ぐ -> 有効)
  • BANドメイン対象: ad.com

下準備

1. 仮想ドメイン登録

$ sudo vi /etc/hosts

下記仮想ドメインを追記します。

hosts
...

127.0.0.1 www.ad.com
127.0.0.1 www.test1.com
127.0.0.1 www.test2.com
127.0.0.1 www.test3.com
127.0.0.1 www.test4.com
127.0.0.1 www.test5.com

2. Apache 起動

最近のMacは最初からApacheが入っているので便利です。

# 起動
sudo apachectl start
# 停止
sudo apachectl stop
# 再起動
sudo apachectl restart

とりあえず、Apacheを起動した状態にしときます。

3. テスト用 HTMLファイル作成

# Apache documentの配下に入る
$ cd /Library/WebServer/Documents/

# テスト用 HTMLファイル3つを作成
$ sudo vi media.html
$ sudo vi redirect.html
$ sudo vi cookie.html
media.html
<html>
  <body>
    <a href='http://www.ad.com/redirect.html' target='_self'>
      <img src='https://lumiere-a.akamaihd.net/v1/images/the-last-jedi-theatrical-poster-tall-a_6a776211.jpeg?region=0%2C0%2C1536%2C864&width=768'>
    </a>
    <iframe src='http://www.ad.com/cookie.html' />
</body>
</html>
redirect.html
<html>
  <head>
    <script>
      var id = "BB-8";
      var expire = new Date((new Date()).getTime() + (3600 * 24 * 1000)); // after 1 day
      document.cookie = 'ID=' + id + '; path=/; domain=.ad.com; expires=' + expire.toUTCString() + ";";
      location.href = "http://www.starwars.com";
    </script>
  </head>
</html>
cookie.html
<html>
  <body>
    <h2>Cookie of ad.com domain</h2>
    <p id="id"></p>
    <script>
      if (document.cookie) {
        document.getElementById('id').innerHTML = document.cookie;
      }
    </script>
  </body>
</html>

BAN 実験

Safari 11で http://www.test1.com/media.html を開く。
ad.com という 3rd-party のクッキーはまだないので、下の「Cookie of ad.com domain」欄に何も表示されません。

画像をクリックしたら、ad.comのページを経由して広告ページ( http://www.starwars.com ) にリダイレクトします。
途中 ad.comドメインのIDクッキーが作られます。

もう一度、http://www.test1.com/media.html にアクセスしたら、下の「Cookie of ad.com domain」欄にID=BB-8 が表示されますね。
※ それは、3rd-party cookie として、ad.comドメインのIDクッキーがまだ読める証拠です。

繰り返し、下記3つドメインの media.htmlページを開いて、画像をクリックして広告ページに飛ばせます。
http://www.test2.com/media.html
http://www.test3.com/media.html
http://www.test4.com/media.html
それぞれ、media.html ページの下の「Cookie of ad.com domain」欄にID=BB-8 が表示されましたね。

最後に、五つ目ドメインのmedia.htmlページを開く。
http://www.test5.com/media.html
ページの下の「Cookie of ad.com domain」欄にID=BB-8 が消えました!
そして、他のページに入っても 3rd-partyとしてad.comのcookieが読めなくなりました!

ということは、ITP機能発動!
ad.comドメインは見事にトラッカーと認定され、BANされました!!

リソースのドメイン数が4に達した時点で、トラッカー判定されることを確認しました。

こちらの記事 に書いたこと、再現しましたね。

終わりに

ITP 機能に関してまだいくつ特性がありますが、機会があれば続々紹介したいと思います。

15
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
5