P3P 代表「隱私偏好平台」(Platform for Privacy Preferences),是一種瀏覽器/網路標準,旨在促進更完善的消費者網路隱私控制。目前(截至 2014 年),在所有主要瀏覽器中,只有 Internet Explorer 支援它。P3P 最常在處理舊版應用程式時發揮作用。
許多現代組織正刻意忽略 P3P。以下是 Facebook 對此議題的看法
建立 P3P 的組織,全球資訊網協會(World Wide Web Consortium),幾年前已暫停對此標準的工作,因為大多數現代網路瀏覽器並不完全支援 P3P。因此,P3P 標準現在已經過時,無法反映目前網路上使用的技術,因此大多數網站目前沒有 P3P 政策。
另請參閱:http://www.zdnet.com/blog/facebook/facebook-to-microsoft-p3p-is-outdated-what-else-ya-got/9332
儘管如此,有時您還是必須支援 P3P。
幸運的是,存在一些不同的模組,透過啟用相關的 P3P 標頭,將 P3P 支援帶入 Express 和 Sails。若要使用其中一個模組來處理 P3P 標頭,請依照以下指示從 npm 安裝它,然後開啟專案中的 config/http.js
並將其配置為自訂中介軟體。為此,將您的 P3P 中介軟體定義為 "p3p",並將字串 "p3p" 新增到您的 middleware.order
陣列中,放在您希望它在中介軟體鏈中執行的任何位置(一個好的位置可能是緊接在 cookieParser
之前)
例如在 config/http.js
中
// .....
module.exports.http = {
middleware: {
p3p: require('p3p')(p3p.recommmended), // <==== set up the custom middleware here and named it "p3p"
order: [
'startRequestTimer',
'p3p', // <============ configured the order of our "p3p" custom middleware here
'cookieParser',
'session',
'bodyParser',
'handleBodyParserError',
'compress',
'methodOverride',
'poweredBy',
'$custom',
'router',
'www',
'favicon',
'404',
'500'
],
// .....
}
};
查看以下範例以獲得更多指導,並務必追蹤連結以查看您正在使用的模組的文件,以取得最新資訊、其功能的比較分析、任何最近的錯誤修復以及進階使用詳細資訊。
node-p3p
是在 MIT 授權條款 下的開放原始碼。
# In your sails app
npm install p3p --save
然後在 config/http.js
中的 middleware
配置物件中
// ...
// node-p3p provides a recommended compact privacy policy out of the box
p3p: require('p3p')(require('p3p').recommended)
// ...
lusca
是在 Apache 授權條款 下的開放原始碼
# In your sails app
npm install lusca --save
然後在 config/http.js
中的 middleware
配置物件中
// ...
// "ABCDEF" ==> The compact privacy policy to use.
p3p: require('lusca').p3p('ABCDEF')
// ...