Fixed the session ID update vulnerability in java or jsp.

Source: Internet
Author: User

Scanned by appscan. 1. Cause of the vulnerability: AppScan scans the cookies before and after "Logon behavior", and records the JSESSIONOID (or other Cookie IDS Based on the application. If the value in the cookie does not change after logon, the session ID is regarded as not updated. 2. In AppScan, modification suggestions are provided for "session ID not updated". Generally, it is recommended that a new session be generated for the user to log on when authentication is successful. Prevents users from manipulating session IDs. Do not accept the session ID provided by the user when logging on to the browser. 3. Modify the settings as follows: during logon, copy the Code <% session. invalidate (); Cookie [] cookies = request. getCookies (); if (null! = Cookies) {for (int I = 0; I <cookies. length; I ++) {if ("JSESSIONID "). using signorecase (cookies [I]. getName () {cookies [I]. setMaxAge (0); response. addCookie (cookies [I]) ;}}%> copy code to exit: Copy Code <% reponse. setHeader ("Pragma", "No-cache"); response. setHeader ("Cache-Control", "no-cache"); response. setDateHeader ("Expires", 0); session = request. getSession (true); session. invalidate (); %> copy code 4. implementation in spring security: Step 1: extract the old sess All attributes and values in ion. Step 2: make the old session invalid. Step 3: generate a new session and assign all attributes and values of the old session to the new session. Copy the code/*** Called to extract the existing attributes from the session, prior to invalidating it. if * {@ code migrateAttributes} is set to {@ code false}, only Spring Security attributes will be retained. * All application attributes will be discarded. * <p> * You can override this method to control exactly what is transferred to the new session. ** @ param session the session from which the attribu Tes shocould be extracted * @ return the map of session attributes which shocould be transferred to the new session */protected Map <String, Object> extractAttributes (HttpSession session) {return createMigratedAttributeMap (session);} final HttpSession applySessionFixation (HttpServletRequest request) {HttpSession session = request. getSession (); String originalSessionId = session. getId (); Map <String, Object> attributesToMigrate = extractAttributes (session); session. invalidate (); session = request. getSession (true); // we now have a new session transferAttributes (attributesToMigrate, session); return session;} copy the code Note: session = request. getSession (true); // we now have a new session getSession public HttpSession getSession (boolean create) Returns the current HttpSession associated with this reque St or, if there is no current session and create is true, returns a new session. if create is false and the request has no valid HttpSession, this method returns null. to make sure the session is properly maintained, you must call this method before the response is committed. if the container is using cookies to maintain session integrity and is asked to create a new session when the response I S committed, an IllegalStateException is thrown. parameters: true-to create a new session for this request if necessary; false to return null if there's no current session Returns: the HttpSession associated with this request or null if create is false and the request has no valid session. 5. summary: Use session when logging on or exiting. the invalidate method does not update the session mark, and the method is the easiest. The spring-security method is used for comprehensive modification.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.