亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 基礎常識 > 正文

http協議之cookie標準RFC6265介紹

2020-07-05 18:03:33
字體:
來源:轉載
供稿:網友

 

cookie是現代web系統開發中非常重要的一個技術,最近對cookie標準RFC6265進行了了解,從中選取了部分內容。

1.cookie的主要作用

因為HTTP協議是無狀態的,對于一個瀏覽器發出的多次請求,WEB服務器無法區分是不是來源于同一個瀏覽器。所以,需要額外的數據用于維護會話。 Cookie 正是這樣的一段隨HTTP請求一起被傳遞的額外數據。

2.cookie的主要作用

除了name、value這兩個必備屬性外,還有下面幾個可選屬性(這些屬性名都是大小寫不敏感的,并且只要設置了瀏覽器是必須處理的),分別控制cookie的生存周期、可見性、安全性。

2.1) expires:絕對過期時間

如果這個屬性的值不能被轉換為日期,客戶端會忽略該屬性。當同一個cookie兩次請求的expires值不相同時,新的 可能 會替換舊的。
If the attribute-value failed to parse as a cookie date, ignore the cookie-av.
If the expiry-time is later than the last date the user agent can represent, the user agent MAY replace the expiry-time with the last representable date.
If the expiry-time is earlier than the earliest date the user agent can represent, the user agent MAY replace the expiry-time with the earliest representable date

2.2)Max-Age:相對過期時間,以秒為單位。如果該屬性的值不是數字,客戶端將不做處理。

If the first character of the attribute-value is not a DIGIT or a '-' character, ignore the cookie-av.
If the remainder of attribute-value contains a non-DIGIT character, ignore the cookie-av.
If delta-seconds is less than or equal to zero (0), let expiry-time be the earliest representable date and time. Otherwise, let the expiry-time be the current date and time plus delta-seconds seconds.

Max-age和expires這兩個屬性控制cookie生命周期。 如果兩個都設置了,以Max-Age為準。 默認情況下,cookie是暫時存在的,他們存儲的值只在瀏覽器會話期間存在。當瀏覽器推出后,這些值也就丟失了.
If a cookie has neither the Max-Age nor the Expires attribute, the user agent will retain the cookie until 'the current session is over' (as defined by the user agent)。

2.3)path:指定了與cookie關聯在一起的網頁,默認情況下,cookie會和創建它的網頁以及與這個網頁處于同一個目錄下的網頁和處于該目錄的子目錄下的網頁關聯,同時不能用這個屬性來確定安全性

The scope of each cookie is limited to a set of paths, controlled by the Path attribute. If the server omits the Path attribute, the user agent will use the 'directory' of the request-uri’s path component as the default value.
The user agent will include the cookie in an HTTP request only if the path portion of the request-uri matches (or is a subdirectory of) the cookie’s Path attribute, where the %x2F ('/') character is interpreted as a directory separator.
Although seemingly useful for isolating cookies between different paths within a given host,the Path attribute cannot be relied upon for security

2.4)domain:如果沒有設置cookie的domain值,該屬性的默認值就是創建cookie的網頁所在的服務器的主機名

If the server omits the Domain attribute, the user agent will return the cookie only to the origin server。但不能將一個cookie的域設置成服務器所在的域之外的域 
The user agent will reject cookies unless the Domain attribute specifies a scope for the cookie that would include the origin server. For example, the user agent will accept a cookie with a Domain attribute of 'example.com' or of 'foo.example.com' from foo.example.com, but the user agent will not accept a cookie with a Domain attribute of 'bar.example.com' or of 'baz.foo.example.com'. NOTE: For security reasons, many user agents are configured to reject Domain attributes that correspond to 'public suffixes'. For example, some user agents will reject Domain attributes of 'com' or 'co.uk'.
When a user agent receives a Set-Cookie header field in an HTTP response, the user agent MAY ignore the Set-Cookie header field in its entirety. For example, the user agent might wish to block responses to 'third-party' requests from setting cookies。

2.5)secure:它指定了在網絡上如何傳輸cookie值。默認情況下,cookie是不安全的,也就是說,他們是通過一個普通的、不安全的http鏈接傳輸的。但是如果將cookie標記為安全的,那么它將只在瀏覽器和服務器通過https或其他安全協議鏈接是才被傳輸。這個屬性只能保證cookie是保密的

The Secure attribute limits the scope of the cookie to 'secure' channels (where 'secure' is defined by the user agent). When a cookie has the Secure attribute, the user agent will include the cookie in an HTTP request only if the request is transmitted over a secure channel (typically HTTP over Transport Layer Security (TLS)

2.6)HttpOnly:設為true后,只能通過http訪問,不能通過documents.cookie獲取設定為httponly的鍵值,防止xss讀取cookie。

httpOnly屬性和secure是獨立的,一個cookie可以同時設置這兩個屬性。
The HttpOnly attribute limits the scope of the cookie to HTTP requests. In particular, the attribute instructs the user agent to omit the cookie when providing access to cookies via 'non-HTTP' APIs (such as a web browser API that exposes cookies to scripts). Note that the HttpOnly attribute is independent of the Secure attribute: a cookie can have both the HttpOnly and the Secure attribute.

2.7)cookie屬性其他相關內容

User agents ignore unrecognized cookie attributes (but not the entire cookie).
To maximize compatibility with user agents, servers that wish to store arbitrary data in a cookie-value SHOULD encode that data, for example, using Base64 [RFC4648].
To maximize compatibility with user agents, servers SHOULD NOT produce two attributes with the same name in the same set-cookie-string.
If the user agent receives a new cookie with the same cookie-name, domain-value, and path-value as a cookie that it has already stored, the existing cookie is evicted and replaced with the new cookie. Notice that servers can delete cookies by sending the user agent a new cookie with an Expires attribute with a value in the past.

3.cookie值在何處設置

通常cookie值是在服務端設置,但也可以通過js在客戶端設置,另外
3.1)編碼方式(Java中的httpclient包)的http請求可以直接在請求頭上加入cookie;
3.2)iOS的UIWebview可以在loadRequest構造帶cookie的reqeust;
3.3)Android的Webview可以通過CookieManager來設置cookie;

4.cookie如何傳輸及規則

4.1服務端—》客戶端

通過http的response頭,會將服務端設置的所有的cookie都發送到客戶端,發送的內容是cookie的name、value及已設置的全部屬性

4.2cookie屬性其他相關內容

通過http的request頭,瀏覽器也不是發送它所接收到的所有Cookie,它會檢查當前要請求的域名以及目錄, 只要這二項目與Cookie對應的Domain和Path匹配,才會發送。對于Domain則是按照尾部匹配的原則進行的。發送的內容只有name和value,其他的屬性是不發送的。
Each cookie-pair represents a cookie stored by the user agent. The cookie-pair contains the cookie-name and cookie-value the user agent received in the Set-Cookie header.
Notice that the cookie attributes are not returned.
因而當客戶端發送兩個同名的cookie時,服務端是無法區分這兩個cookie的歸屬。
Although cookies are serialized linearly in the Cookie header, servers SHOULD NOT rely upon the serialization order. In particular, if the Cookie header contains two cookies with the same name (e.g., that were set with different Path or Domain attributes), servers SHOULD NOT rely upon the order in which these cookies appear in the header.

5.cookie是否可以被截獲

有兩種方法可以截獲他人的cookie,
5.1). 通過XSS腳步攻擊, 獲取他人的cookie
5.2.) 想辦法獲取別人電腦上保存的cookie文件(這個比較難)

6.cookie是否可以被非法修改

可以通過一些插件(如edit this cookie)或者其他技術手段進行修改。Secure屬性也有其局限性。
Although seemingly useful for protecting cookies from active network attackers, the Secure attribute protects only the cookie’s confidentiality. An active network attacker can overwrite Secure cookies from an insecure channel, disrupting their integrity

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
色婷婷综合久久久久中文字幕1| 狠狠色香婷婷久久亚洲精品| 粉嫩老牛aⅴ一区二区三区| 色av吧综合网| 国产性猛交xxxx免费看久久| 国产成人精品久久二区二区| 国产精品入口免费视| 日韩免费高清在线观看| 亚洲欧美另类国产| 亚洲欧美日韩精品| 2019亚洲男人天堂| 亚洲成年人影院在线| 久久免费精品日本久久中文字幕| 亚洲国产中文字幕久久网| 欧美激情视频给我| 久久久www成人免费精品| 午夜精品久久久久久久99黑人| 日韩精品电影网| 国产精品白丝jk喷水视频一区| 九九热这里只有精品6| 成人www视频在线观看| 国产欧美日韩中文| 黄色一区二区在线| 欧美日韩国产一区二区三区| 7m精品福利视频导航| 美女999久久久精品视频| 免费91麻豆精品国产自产在线观看| 亚洲成人a**站| 欧美怡春院一区二区三区| 久久人人爽亚洲精品天堂| 欧美国产日韩中文字幕在线| 国产美女精品视频| 午夜精品久久久久久99热软件| 日本在线观看天堂男亚洲| 深夜成人在线观看| 欧美一区二区三区四区在线| 青草青草久热精品视频在线网站| 久久久久一本一区二区青青蜜月| 在线播放日韩精品| 亚洲国产成人精品久久久国产成人一区| 欧美日韩亚洲一区二区三区| 91精品视频观看| 97国产精品免费视频| 国产亚洲欧美aaaa| 国产成人久久精品| 久久久久久久久电影| 色老头一区二区三区在线观看| 欧美www视频在线观看| 日本免费一区二区三区视频观看| 欧美国产日韩精品| 成人美女av在线直播| 久久久久久国产免费| 色偷偷av一区二区三区| 国产精品视频99| 欧美在线观看网站| 一区二区三欧美| 国产精品视频大全| 69久久夜色精品国产69乱青草| 日本成人激情视频| 欧美激情三级免费| 国产精品手机播放| 欧美精品18videosex性欧美| 国产精品91免费在线| 亚洲午夜色婷婷在线| 亚洲人成五月天| 亚洲欧美三级在线| 久久精品99无色码中文字幕| 日本精品视频在线观看| 国产综合色香蕉精品| 一本色道久久综合狠狠躁篇怎么玩| 国产亚洲欧美视频| 久久久免费精品视频| 久久人91精品久久久久久不卡| 亚洲欧美福利视频| 成人国产精品久久久久久亚洲| 国产日韩中文在线| 亚洲视频欧洲视频| 精品伊人久久97| 日韩精品极品视频免费观看| 91久热免费在线视频| 色婷婷综合成人av| 俺去了亚洲欧美日韩| 亚洲第一中文字幕| 国内久久久精品| 国产成人精品久久亚洲高清不卡| 亚洲国产高清高潮精品美女| 大量国产精品视频| 久久精品国产亚洲精品| 欧美黑人xxxⅹ高潮交| 不卡伊人av在线播放| 久久亚洲国产精品成人av秋霞| 欧美激情精品久久久久| 国产日产亚洲精品| 亚洲天堂网站在线观看视频| 欧美激情一二区| 国产欧美一区二区白浆黑人| 国产91精品久久久久久久| 欧美国产日韩xxxxx| 亚洲男人天堂九九视频| 亚洲女人天堂网| 国产欧美精品日韩| 日韩成人激情视频| 操日韩av在线电影| 亚洲а∨天堂久久精品9966| 国产精品视频xxx| 亚洲韩国欧洲国产日产av| 成人黄色在线观看| 欧美亚洲国产成人精品| 久久免费精品日本久久中文字幕| 亚洲精品乱码久久久久久按摩观| 亚洲小视频在线| 国产精品美女av| 亚洲欧洲在线看| 91精品在线看| 亚洲电影免费观看高清完整版在线观看| 国产欧美精品在线| 欧美亚洲视频在线观看| 国产精品久久精品| 日韩激情av在线免费观看| 欧美激情欧美狂野欧美精品| 国产精品成人一区| 欧美激情视频在线免费观看 欧美视频免费一| 国产精品美腿一区在线看| 亚洲国产精品人久久电影| 亚洲美女激情视频| 国产91精品久久久久久| 久久天天躁日日躁| 国产视频999| 色99之美女主播在线视频| 亚洲精品美女久久| 日韩av影视综合网| 日韩精品在线免费观看| 亚洲成人激情在线观看| 国产精品欧美日韩久久| 日韩专区在线播放| 成人黄色在线播放| 亚洲精品一区中文字幕乱码| 91精品免费久久久久久久久| 亚洲免费人成在线视频观看| 亚洲伊人久久大香线蕉av| 国产精品热视频| 91国产美女在线观看| 成人免费xxxxx在线观看| 日韩电影视频免费| 日韩中文字幕亚洲| 欧美激情精品在线| 亚洲欧洲成视频免费观看| 亚洲欧美精品一区| 97视频国产在线| 亚洲国产精品久久久| 中文字幕精品国产| 久久人人爽人人爽爽久久| 日韩精品免费在线视频观看| 成人性生交大片免费看小说| 69国产精品成人在线播放| 国产在线日韩在线| 亚洲欧美在线一区二区| 欧美激情一区二区三区高清视频| 国产日韩在线播放| 91在线视频精品| 成人激情视频在线播放| 国内精品美女av在线播放| 日韩高清中文字幕| 77777亚洲午夜久久多人|