屬性介紹:
1) secure屬性
當設置為true時,表示創建的 Cookie 會被以安全的形式向服務器傳輸(ssl),即
只能在 HTTPS 連接中被瀏覽器傳遞到服務器端進行會話驗證,
如果是 HTTP 連接則不會傳遞該信息,所以不會被竊取到Cookie 的具體內容。
2 )HttpOnly屬性
如果在Cookie中設置了"HttpOnly"屬性,那么通過程序(JS腳本、Applet等)將無法讀取到Cookie信息,這樣能有效的防止XSS攻擊。
3)X-Frame-Options 響應頭
X-Frame-Options HTTP 響應頭,表示 是否允許一個頁面在 <frame>, </iframe> 或者 <object> 中展現的標記。
通過設置 X-Frame-Options 阻止站點內的頁面被其他頁面嵌入從而防止點擊劫持。X
X-Frame-Options 有三個值:
DENY :該頁面不允許在 frame 中展示,即便是在相同域名的頁面中嵌套也不允許。
SAMEORIGIN :該頁面可在相同域名頁面的 frame 中展示。
ALLOW-FROM uri:該頁面可在指定來源的 frame 中展示。
2.HttpOnly,Secure的設置樣例:
1)java代碼處理方式:
//設置cookie
response.setHeader("Set-Cookie", "JSESSIONID=" + sessionid + ";Secure;HttpOnly")//設置Secure;HttpOnly
response.setHeader("x-frame-options", "SAMEORIGIN");//設置x-frame-options
2)tomcat處理方式
對 tomcat/conf/context.xml 修改
<Context useHttpOnly="true">
對 tomcat/conf/server.xml 修改
(java代碼和配置,二選一即可,目前,我只有java代碼方式生效)
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000" redirectPort="8443" secure="true"/>
————————————————————————————————————————
附1:
HttpOnly之Apache官網描述
refer :http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
useHttpOnly |
Should the HttpOnly flag be set on session cookies to prevent client side script from accessing the session ID? Defaults to |