转:简单介绍 P3P 技术
原文来自于:http://blog.csdn.net/ghj1976/article/details/4889219
以 Internet Explorer 为例,默认情况下,IE的隐私策略如下图所设:
(图一)
请注意其中这一条:阻止保存可用来联系您的信息而没有您的明确同意的第三方Cookie。
下面我们首先来演示一下,这一条起作用的情况:
站点 b.com 有这样一个网页: http://b.com/WebApp_P3P/p3p.htm
这个页面的源代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>P3P Test</title>
</head>
<body>
1232sasdsa<br/>
<iframe src="http://a.net/WebApp_P3P/a_setcookie.aspx" ></iframe>
</body>
</html>
这个源代码中用 iframe 包含了 a.net 站点的一个页面。 这时候所谓的的第一方站点就是 b.com 站点,第三方站点就是 a.net 站点。
http://a.net/WebApp_P3P/a_setcookie.aspx 的功能很简单,就是写一个长期保存的Cookie,代码如下:
<%@ Page Language="C#" AutoEventWireup="true" %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie hc = new HttpCookie("ghj", string.Format("aaaa_{0}_{1}", DateTime.Now, Request.Url));
hc.Domain = ".a.net";
hc.Expires = DateTime.Now.AddDays(14);
hc.Path = "/";
Response.Cookies.Add(hc);
Response.Write("aaaa");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>p3p test</title>
</head>
<body>
</body>
</html> 当我们访问 http://b.com/WebApp_P3P/p3p.htm 地址时,情况如下,
(图二)
注意, 中间的 (图三)提示,我们双击这个图标可以看到下面窗体
(图四)
我们另外写一个页面 http://a.net/WebApp_P3p/a_getcookie.aspx 来获取Cookie, 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies.AllKeys.Contains<string>("ghj"))
this.Label1.Text = Request.Cookies["ghj"].Value;
else
this.Label1.Text = "null";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>P3P Demo</title>
</head>
<body>
<form id="form1" runat="server" style="height:100%">
<asp:Label ID="Label1" runat="server" Text="Label" /><br/>
</form>
</body>
</html>
我们首先访问 http://b.com/WebApp_P3P/p3p.htm ; 然后访问 http://a.net/WebApp_P3p/a_getcookie.aspx 这个页面,我们会发现,没有Cookie。
类似的,我们用下面几种写法,都是一样的,无法在第三方网站创建Cookie。
<script src="http://a.net/WebApp_P3P/a_setcookie.aspx" ></script>
<img src="http://a.net/WebApp_P3P/a_setcookie.aspx" />
<!-- 只要是任何访问第三方网站的方式,第三方网站都无法书写Cookie,这里只只罗列了几种常见的方式 -->
上面的演示,你本机也可以进行,只需要做如下修改:
使用后面命令 notepad C:/Windows/System32/drivers/etc/hosts 打开 hosts文件,确保 hosts文件增加下面2两行:
127.0.0.1 a.net
127.0.0.1 b.com
如果解决这个问题呢?
一个非常简单的解决方案就是修改 http://a.net/WebApp_P3P/a_setcookie.aspx 文件,在其中增加下面一行代码:
Response.Headers.Add("P3P", "CP=/"CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR/"");
这行代码就是一个简单的P3P应用,那P3P又是啥呢?
P3P(Platform for Privacy Preferences)(隐私权偏好选项平台)是W3C(World Wide Web Consortium)公布的一项隐私保护推荐标准。Microsoft Internet Explorer 6 (IE6) 是第一个支持这项新隐私权标准的浏览器。 Firefox目前还不支持 P3P 安全特性。 采用 P3P 之后,您可以设置浏览器自动侦测网站是否:收集个人标识信息、使用这些信息创建用户档案、或允许到访者拒绝数据收集。
具备 P3P 能力的浏览器具有一些可供您选择的默认选项。 或者您也可以通过回答问题的方式(例如您愿意分享哪些数据、愿意接受哪些类型的 Cookie 文件)自定义您的设置。 当您在 Web 浏览时,这个软件会判断您的隐私权偏好选项是否与网站的数据收集做法匹配。
具备 P3P 能力的浏览器会特别注意 Cookie。 Cookie 是留存在您计算机硬盘上的一段文本,它可以让 Web 应用程序以个体方式对您响应。 通过收集和记忆您的偏好选项信息,Web 应用程序可以根据您的需求、喜欢什么、不喜欢什么等来修改它的运作模式。 使用具备 P3P 能力的浏览器,您可以选择是否接受各种类型的 Cookie,例如阶段性(暂时性)、永久性、在指定的网域之内或之外(第三方),以及有没有特殊的 ”P3P 精简政策” (P3P compact policy) 文件。 精简 P3P 政策描述了给定 Cookie 的属性。
对于上面的只是, Internet Explorer 就体现在本文第一张图上对浏览器隐私的设置上。以及进一步的设置中,图四中,我们选中站点,摘要按钮就可以用了,点击摘要按钮可以看到下面信息:
(图五)选中站点,摘要按钮就可以用了,点击摘要按钮
(图六)隐私策略调整窗口
从技术上看,P3P包括了两个组件:一个放在服务器端;另外一个放在客户端,形成一个用户代理。当用户登陆网站的时候,服务器端的组件根据网站的要求,会自动生成XML语言形式的用户个人处理策略,这就像是贴在商店橱窗外的公众告示,而客户端的组件就将这个“公众告示”提供给用户。
上面例子中隐私策略中 CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR 的意思是啥。 Fiddler可以方便的知道,在Fiddler 中我们可以看到如下信息:
Response sets a cookie:
Set-Cookie: ghj=aaaa_2009/11/27 15:55:56_http://a.net/WebApp_P3P/a_setcookie.aspx; domain=.a.net; expires=Fri, 11-Dec-2009 07:55:56 GMT; path=/
P3P Header is present:
CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"
Compact Policy token is present. A trailing 'o' means opt-out, a trailing 'i' means opt-in.
CURa
Information is used to complete the activity for which it was provided.
ADMa
Information may be used for the technical support of the Web site and its computer system.
DEVa
Information may be used to enhance, evaluate, or otherwise review the site, service, product, or market.
PSAo
Information may be used to create or build a record of a particular individual or computer that is tied to a pseudonymous identifier, without tying identified data (such as name, address, phone number, or email address) to the record. This profile will be used to determine the habits, interests, or other characteristics of individuals for purpose of research, analysis and reporting, but it will not be used to attempt to identify specific individuals.
PSDo
Information may be used to create or build a record of a particular individual or computer that is tied to a pseudonymous identifier, without tying identified data (such as name, address, phone number, or email address) to the record. This profile will be used to determine the habits, interests, or other characteristics of individuals to make a decision that directly affects that individual, but it will not be used to attempt to identify specific individuals.
OUR
We share information with ourselves and/or entities acting as our agents or entities for whom we are acting as an agent.
BUS
Info is retained under a service provider's stated business practices. Sites MUST have a retention policy that establishes a destruction time table. The retention policy MUST be included in or linked from the site's human-readable privacy policy.
UNI
Non-financial identifiers, excluding government-issued identifiers, issued for purposes of consistently identifying or recognizing the individual. These include identifiers issued by a Web site or service.
PUR
Information actively generated by the purchase of a product or service, including information about the method of payment.
INT
Data actively generated from or reflecting explicit interactions with a service provider through its site -- such as queries to a search engine, or logs of account activity.
DEM
Data about an individual's characteristics -- such as gender, age, and income.
STA
Mechanisms for maintaining a stateful session with a user or automatically recognizing users who have visited a particular site or accessed particular content previously -- such as HTTP cookies.
PRE
Data about an individual's likes and dislikes -- such as favorite color or musical tastes.
COM
Information about the computer system that the individual is using to access the network -- such as the IP number, domain name, browser type or operating system.
NAV
Data passively generated by browsing the Web site -- such as which pages are visited, and how long users stay on each page.
OTC
Other types of data not captured by the above definitions.
NOI
Web Site does not collected identified data.
DSP
The privacy policy contains DISPUTES elements.
COR
Errors or wrongful actions arising in connection with the privacy policy will be remedied by the service.
Validate at: http://www.w3.org/P3P/validator.html
Learn more at: http://www.fiddler2.com/redir/?id=p3pinfo
P3P这个Http头的写法有很多组合,自己写很痛苦,通过下面这个连接 http://www.w3.org/P3P/details.html 您可以找到一些P3P策略生成器软件包。(虽然如果在Google上搜索,您会发现更多搜索结果,但提供免费使用的好象只有IBM的P3P策略编辑器IBM's P3P Policy Editor。)
注意:
Visual Studio 自带的开发站点(ASP.NET Development Server)是不支持这个功能的,它会报错误:This operation requires IIS integrated pipeline mode.
参考资料:
用P3P解决第三方cookie存取的问题
http://www.javaeye.com/topic/94336
IBM P3P Policy Editor
http://www.alphaworks.ibm.com/tech/p3peditor
How to configure IIS to use Platform for Privacy Preferences (P3P)
http://support.microsoft.com/kb/324013/en-us
How to Deploy P3P Privacy Policies on Your Web Site
http://msdn.microsoft.com/en-us/library/ms537341(VS.85).aspx
Add a Custom HTTP Response Header (IIS 7)
http://technet.microsoft.com/en-us/library/cc753133(WS.10).aspx
私有参数选择平台——P3P(关于Cookies)
http://www.yxl.cn/Info/20060302,212041,5095.html
使用P3P
http://welcome.hp.com/country/cn/zh/privacy/p3p_popup.html
用P3P header解决iframe跨域访问cookie/session
http://blog.csdn.net/Hashxu/archive/2009/01/02/3684402.aspx
利用P3P跨域传COOKIE
http://hi.baidu.com/thinkinginlamp/blog/item/5e2a02084f1dafd163d9865f.html
使用p3p解决Iframe中cookie跨域问题
http://blog.ntsky.com/p3p-iframe-cookie.html
通过设置P3P头来实现跨域访问COOKIE
http://blog.c114.net/html/38/193738-35549.html
P3P
http://www.hudong.com/wiki/p3p
Cookie, iframe 与 P3P 的那点事儿
http://www.dbanotes.net/web/cookie_p3p.html
Firefox Help: Firefox's Cookie Options
http://mozilla.gunnars.net/firefox_help_firefox_cookie_tutorial.html
ie session丢失 ie中iframe丢失问题
http://wangzi6hao.javaeye.com/blog/531524
转:简单介绍 P3P 技术的更多相关文章
- Lucene.net站内搜索—4、搜索引擎第一版技术储备(简单介绍Log4Net、生产者消费者模式)
目录 Lucene.net站内搜索—1.SEO优化 Lucene.net站内搜索—2.Lucene.Net简介和分词Lucene.net站内搜索—3.最简单搜索引擎代码Lucene.net站内搜索—4 ...
- Linux 下UVC&V4L2技术简单介绍(二)
通过前文Linux 下UVC&V4L2技术简单介绍(一)我们了解了UVC和V4L2的简单知识. 这里是USB设备的文档描写叙述:http://www.usb.org/developers/do ...
- iOS开发多线程篇—多线程简单介绍
iOS开发多线程篇—多线程简单介绍 一.进程和线程 1.什么是进程 进程是指在系统中正在运行的一个应用程序 每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内 比如同时打开QQ.Xcod ...
- Android开发自学笔记(Android Studio)—4.界面编程与View组件简单介绍
一.引言 Android应用开发最重要的一份内容就是界面的开发,无论你程序包含的内容多么优秀,如若没有一个良好的用户交互界面,最终也只是会被用户所遗弃.Android SDK提供了大量功能丰富的UI组 ...
- iOS开发网络篇—简单介绍ASI框架的使用
iOS开发网络篇—简单介绍ASI框架的使用 说明:本文主要介绍网络编程中常用框架ASI的简单使用. 一.ASI简单介绍 ASI:全称是ASIHTTPRequest,外号“HTTP终结者”,功能十分强大 ...
- iOS开发数据库篇—SQLite简单介绍
iOS开发数据库篇—SQLite简单介绍 一.离线缓存 在项目开发中,通常都需要对数据进行离线缓存的处理,如新闻数据的离线缓存等. 说明:离线缓存一般都是把数据保存到项目的沙盒中.有以下几种方式 (1 ...
- iOS开发UI篇—Quartz2D简单介绍
iOS开发UI篇—Quartz2D简单介绍 一.什么是Quartz2D Quartz 2D是⼀个二维绘图引擎,同时支持iOS和Mac系统 Quartz 2D能完成的工作: 绘制图形 : 线条\三角形\ ...
- iOS开发拓展篇-XMPP简单介绍
iOS开发拓展篇-XMPP简单介绍 一.即时通讯简单介绍 1.简单说明 即时通讯技术(IM)支持用户在线实时交谈.如果要发送一条信息,用户需要打开一个小窗口,以便让用户及其朋友在其中输入信息并让交谈双 ...
- VPN理论简单介绍(转载)
标签:VPN理论简单介绍 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://lvnian.blog.51cto.com/715528 ...
随机推荐
- WCF服务部署到IIS上,然后通过web服务引用方式出现错误的解决办法
本文转载:http://www.cnblogs.com/shenba/archive/2012/01/06/2313932.html 昨天在用IIS部署一个WCF服务时,碰到了如下错误: 理解了文档内 ...
- win8 64位 mysql安装 Configuration file my.ini error code -1
问题如题,解决方法: 1.由于目录中纯在中文,所以导致代码错误.故而把目录设置成全英文的. 2.下载64位mysql安装,安装32位mysql也会出现此问题.
- 程序猿接私活经验总结,来自csdn论坛语录
下面为网上摘录,以做笔记: 但是到网上看看,似乎接私活也有非常多不easy,技术问题本身是个因素,还有非常多有技术的人接私活时被骗,或者是合作到最后以失败告终,所以想请有经验的大侠们出来指点一下,接私 ...
- 利用systemtap学习Linux路由代码
http://bbs.chinaunix.net/thread-4090162-1-1.html 一.为什么要这样做读kernel route子系统代码,当我弄懂了数据结构之间的关系以及控制流程后,心 ...
- 使用navicat 11 出现不能返回存储过程结果的问题
问题: 使用navicat 11 调试存储过程,select返回结果,总是不能返回. 原因: 经google发现,navicat仅支持返回10个resultset,超过则不现实. 解决方法: 减少存储 ...
- cocoaPods下载使用记录
cocoaPods下载使用记录 参考地址: 如何在Mac OS 上安装运行Ruby运行环境 http://www.cnblogs.com/daguo/p/4097263.html cocoaPods安 ...
- [转] Node.js 服务端实践之 GraphQL 初探
https://medium.com/the-graphqlhub/your-first-graphql-server-3c766ab4f0a2#.n88wyan4e 0.问题来了 DT 时代,各种业 ...
- android开发之broadcast学习笔记 分类: android 学习笔记 2015-07-19 16:33 32人阅读 评论(0) 收藏
android中的广播用的太多了,今天稍微总结一下. 按注册方式分为两种: 1.静态注册广播: 静态注册广播就是在androidManifest.xml文件中注册广播,假设我们要实现这样一个效果,在一 ...
- Linux软件安装,RPM与YUM
为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/SJQ. http://www.cnblogs.com/shijiaqi1066/p/3843955.html ...
- ASP.NET MVC 中 ActionResult 和 ViewResult 在使用上的区别
如果确认你返回的是一个视图(view),你可以直接返回类型为ViewResult. 如果你并不是很清楚,或者你根本不想去理解这些东西,你可以直接返回ActionResult