HttpCookie.HttpOnly プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HttpCookie.HttpOnly プロパティの意味・解説 

HttpCookie.HttpOnly プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

クライアント側スクリプトCookieアクセスできるかどうかを示す値を取得または設定します

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

Dim instance As HttpCookie
Dim value As Boolean

value = instance.HttpOnly

instance.HttpOnly = value
public bool HttpOnly { get;
 set; }
/** @property */
public boolean get_HttpOnly ()

/** @property */
public void set_HttpOnly (boolean value)

プロパティ
CookieHttpOnly 属性があり、クライアント側スクリプトではアクセスできない場合trueそれ以外場合false既定値false です。

解説解説

Microsoft Internet Explorer バージョン 6 Service Pack 1 以降では Cookieプロパティ HttpOnlyサポートしてます。これを使用すると、Cookie盗難につながるサイトスクリプト脅威軽減できます盗まれCookie には、ASP.NET セッション IDフォーム認証チケットなど、サイトユーザー識別するための機密情報含まれている場合があり、ユーザーなりすました機密情報取得するため攻撃者利用される可能性ありますHttpOnly 属性を持つ Cookie を、このプロパティ対応しているブラウザ受け取った場合クライアント側スクリプトからその Cookieアクセスすることはできません。

注意に関するメモ注意

HttpOnly プロパティtrue設定しても、ネットワーク チャネルアクセスできる攻撃者による Cookie への直接アクセスを防ぐことはできません。このような攻撃からの保護対策には、Secure Sockets Layer (SSL) の使用検討してくださいまた、ワークステーションセキュリティも重要です。悪意のあるユーザーが、開かれたブラウザ ウィンドウ永続的な Cookie存在するコンピュータ使用して正規ユーザーIDWeb サイトアクセスする可能性あります

考えられる攻撃の種類、およびこのプロパティ使用した対策詳細については、「Mitigating Cross-site Scripting With HTTP-only Cookies」を参照してください

使用例使用例

HttpOnly Cookie作成方法、およびクライアントから ECMAScript使用してこれにアクセスできないことを、次のコード例示します

<%@ Page Language="VB" %>

<script runat="server">

  Protected Sub Page_Load(ByVal
 sender As Object, ByVal
 e As System.EventArgs)
    
    ' Create a new HttpCookie.
    Dim myHttpCookie As New
 HttpCookie("LastVisit", DateTime.Now.ToString())

    ' By default, the HttpOnly property is set to false 
    ' unless specified otherwise in configuration.

    myHttpCookie.Name = "MyHttpCookie"
    Response.AppendCookie(myHttpCookie)

    ' Show the name of the cookie.
    Response.Write(myHttpCookie.Name)

    ' Create an HttpOnly cookie.
    Dim myHttpOnlyCookie As New
 HttpCookie("LastVisit", DateTime.Now.ToString())

    ' Setting the HttpOnly value to true, makes
    ' this cookie accessible only to ASP.NET.

    myHttpOnlyCookie.HttpOnly = True
    myHttpOnlyCookie.Name = "MyHttpOnlyCookie"
    Response.AppendCookie(myHttpOnlyCookie)

    ' Show the name of the HttpOnly cookie.
    Response.Write(myHttpOnlyCookie.Name)

  End Sub
  
</script>

<html>
<body>
<script>
function getCookie(NameOfCookie)
{
  if (document.cookie.length > 0) 
  { 
    begin = document.cookie.indexOf(NameOfCookie+"=");
 
    if (begin != -1)
    { 
    begin += NameOfCookie.length+1; 
      end = document.cookie.indexOf(";",
 begin);
      if (end == -1) end
 = document.cookie.length;
      return unescape(document.cookie.substring(begin, end));
       
    } 
  }
  return null;  
}
</script>

<script>

// This code returns the cookie name.
alert("Getting HTTP Cookie");
alert(getCookie("MyHttpCookie"));

// Because the cookie is set to
 HttpOnly,
// this returns null.
alert("Getting HTTP Only Cookie");
alert(getCookie("MyHttpOnlyCookie"));

</script> 

</body>
</html>

<%@ Page Language="C#" %>


<script runat="server">
    void Page_Load(object sender, EventArgs e)
    {
        // Create a new HttpCookie.
        HttpCookie myHttpCookie = new HttpCookie("LastVisit",
 DateTime.Now.ToString());

        // By default, the HttpOnly property is set to false 
        // unless specified otherwise in configuration.

        myHttpCookie.Name = "MyHttpCookie";
        Response.AppendCookie(myHttpCookie);

        // Show the name of the cookie.
        Response.Write(myHttpCookie.Name);

        // Create an HttpOnly cookie.
        HttpCookie myHttpOnlyCookie = new HttpCookie("LastVisit",
 DateTime.Now.ToString());

        // Setting the HttpOnly value to true, makes
        // this cookie accessible only to ASP.NET.

        myHttpOnlyCookie.HttpOnly = true;
        myHttpOnlyCookie.Name = "MyHttpOnlyCookie";
        Response.AppendCookie(myHttpOnlyCookie);

        // Show the name of the HttpOnly cookie.
        Response.Write(myHttpOnlyCookie.Name);
    }
</script>


<html>
<body>
<script>
function getCookie(NameOfCookie)
{
    if (document.cookie.length > 0) 
{ 
    begin = document.cookie.indexOf(NameOfCookie+"="); 
    if (begin != -1)
   { 
    begin += NameOfCookie.length+1; 
      end = document.cookie.indexOf(";", begin);
      if (end == -1) end = document.cookie.length;
      return unescape(document.cookie.substring(begin, end));
       
      } 
  }
return null;  
}
</script>

<script>

    // This code returns the cookie name.
    alert("Getting HTTP Cookie");
    alert(getCookie("MyHttpCookie"));

    // Because the cookie is set to HttpOnly,
    // this returns null.
    alert("Getting HTTP Only Cookie");
    alert(getCookie("MyHttpOnlyCookie"));

</script> 


</body>
</html>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

HttpCookie.HttpOnly プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HttpCookie.HttpOnly プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS