システムプログラム(第9回): World Wide Webでのcookie

                                       筑波大学 システム情報系 情報工学域
                                       新城 靖
                                       <yas@cs.tsukuba.ac.jp>

このページは、次の URL にあります。
http://www.coins.tsukuba.ac.jp/~syspro/2022/2022-07-20/www-cookie.html
あるいは、次のページから手繰っていくこともできます。
http://www.coins.tsukuba.ac.jp/~syspro/2022/
http://www.coins.tsukuba.ac.jp/~yas/

セッション管理

CGI は、基本的には1回の操作で完結する。買い物かごを作るには、複数の CGI のプログラムの間で一連の操作を1つの連続したもの(セッション)とし て扱う必要がある。

セッション管理には、次のような方法がある。

セッション管理にクッキーを使う方法は、正しく使えば比較的安全である。し かし、クッキーはセッションを越えて有効なもの、異なるサイトに送られるも のも定義できる。また、クッキーにパスワードを埋め込むという幼稚で危険な 実装も時々見受けられる。

セッションは、認証とは別である。同じ人が複数のセッションを実行すること もある。

WWWで途中経過を保存するためには、cookie が使われる。 cookieは、コンピュータ・サイエンスの専門用語である。 協調して動作しているプログラムの間で、ある一連の作業を識別するための数 を意味する。cookie は、 RPC (Remote Procedure Call) や WWW でよく使われる。

WWW での cookie は、次のような仕組みになっている。

サーバは、その情報を利用して、適切なページ(たとえば前回最後に訪れたペー ジ)を表示させるようにすることができる。

User Agent は、WWW ブラウザと思ってよい。
4.  EXAMPLES

4.1  Example 1

   Most detail of request and response headers has been omitted.  Assume
   the user agent has no stored cookies.

      1. User Agent -> Server

        POST /acme/login HTTP/1.1
        [form data]

        User identifies self via a form.

      2. Server -> User Agent

        HTTP/1.1 200 OK
        Set-Cookie2: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"

        Cookie reflects user's identity.

      3. User Agent -> Server

        POST /acme/pickitem HTTP/1.1
        Cookie: $Version="1"; Customer="WILE_E_COYOTE"; $Path="/acme"
        [form data]

        User selects an item for "shopping basket".

      4. Server -> User Agent

        HTTP/1.1 200 OK
        Set-Cookie2: Part_Number="Rocket_Launcher_0001"; Version="1";
                Path="/acme"

        Shopping basket contains an item.

      5. User Agent -> Server

        POST /acme/shipping HTTP/1.1
        Cookie: $Version="1";
                Customer="WILE_E_COYOTE"; $Path="/acme";
                Part_Number="Rocket_Launcher_0001"; $Path="/acme"
        [form data]

        User selects shipping method from form.

      6. Server -> User Agent

        HTTP/1.1 200 OK
        Set-Cookie2: Shipping="FedEx"; Version="1"; Path="/acme"

        New cookie reflects shipping method.

      7. User Agent -> Server

        POST /acme/process HTTP/1.1
        Cookie: $Version="1";
                Customer="WILE_E_COYOTE"; $Path="/acme";
                Part_Number="Rocket_Launcher_0001"; $Path="/acme";
                Shipping="FedEx"; $Path="/acme"
        [form data]

        User chooses to process order.

      8. Server -> User Agent

        HTTP/1.1 200 OK

        Transaction is complete.

   The user agent makes a series of requests on the origin server, after
   each of which it receives a new cookie.  All the cookies have the
   same Path attribute and (default) domain.  Because the request-URIs
   all path-match /acme, the Path attribute of each cookie, each request
   contains all the cookies received so far.
現在の Cookie の実現では、利用者のプライバシーを犯す危険性が高いという 問題が指摘されている。

普通のWWWサーバでは、要求を送ってきたコンピュータのIPアドレスを記 録しているので、コンピュータ単位でのアクセス状況を記録することはできる が、個人を特定することはできない。

クッキーを利用することにより、コンピュータではなくどの個人がアクセスし てきたかを記録することができる。

クッキーから電子メールのアドレスや氏名まで調べることはできない。 しかし、インターネットをサーフしている間にどこかでそれを打ち込んだが最 後、クッキーと電子メール・アドレスや氏名との対応が記録されてしまう危険 性がある。

参考

RFC2965 HTTP State Management Mechanism

2008年度3学期の「 分散システム」のページも参照。
Last updated: 2022/06/22 15:18:28
Yasushi Shinjo / <yas@cs.tsukuba.ac.jp>