Generally, cookies are obtained from the document object. Now, when setting cookies, the browser generally accepts a parameter called HttpOnly, which is the same as other parameters such as domain. Once this HttpOnly is set, you cannot see the Cookie in the document Object of the browser, and the browser will not be affected when browsing, because the Cookie will be sent out in the browser header (including when ajax is used ), applications generally do not operate on these sensitive cookies in js. For some sensitive cookies, we use HttpOnly. For some cookies that need to be operated in applications, we will not set them, this ensures the security of Cookie information and applications.
If you are using a container compatible with Java EE 6.0, such as Tomcat 7, the Cookie class already has the setHttpOnly method to use the HttpOnly Cookie attribute.
1 cookie. setHttpOnly (true );
The Cookie generated after setting will be added at the end; HttpOnly
In addition, if Session is used, the jsessionid Cookie can be used to enable HttpOnly by using useHttpOnly configuration in Context. For example:
1 <Context path = "" docBase = "D:/WORKDIR/oschina/webapp"
2 reloadable = "false" useHttpOnly = "true"/>
You can also configure the following in web. xml:
1 <session-config>
2 <cookie-config>
3 4 </cookie-config>
5 <session-config>
For. NET 2.0 applications, use the following configuration in the system. web/httpCookies element of web. config to enable HttpOnly:
1 The procedure is as follows:
C #:
1 HttpCookie myCookie = new HttpCookie ("myCookie ");
2 myCookie. HttpOnly = true;
3 Response. AppendCookie (myCookie );
VB. NET:
1 Dim myCookie As HttpCookie = new HttpCookie ("myCookie ")
2 myCookie. HttpOnly = True
3 Response. AppendCookie (myCookie)
. NET 1.1 can only be handled manually:
1 Response. Cookies [cookie]. Path + = "; HttpOnly ";
PHP has supported HttpOnly since version 5.2.0.
1 session. cookie_httponly = True