I am implementing tokens for csrf prevention, I am putting a value of csrf token in session attribute like this :
session.setAttribute("csrfToken", csrfToken);
My login page gets that attribute and submit that csrf token to servlet , My login.jsp looks like this :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags/struts-html" prefix="html" %>
<%@ taglib uri="http://devel.payo.org/tlibs/payo-core" prefix="payo" %>
<%@ page session="true" %>
<html:html>
***<input id="token" type="hidden" value="${sessionScope.csrfToken}" />***
<c:choose><c:when test="${not empty loggedUser}">
<head>
<meta http-equiv="refresh" content="0;URL=${pathPrefix}/home">
</head>
</c:when><c:otherwise>
<jsp:include page="/pages/general/layout/head.jsp" />
<payo:customizedFilePath type="style" name="login.css" var="loginUrl" groupId="${empty loggedUserId ? cookie.groupId.value : ''}" groupFilterId="${empty loggedUserId ? cookie.groupFilterId.value : ''}" />
<link rel="stylesheet" href="<c:url value="${loginUrl}" />">
<jsp:include flush="true" page="/pages/access/includes/loginDefinitions.jsp" />
<payo:includeCustomizedFile type="static" name="login.jsp" groupId="${empty loggedUserId ? cookie.groupId.value : ''}" groupFilterId="${empty loggedUserId ? cookie.groupFilterId.value : ''}" />
<script>
if (!is.ie6) {
var td = $('loginRegistration');
var div = $('loginRegistrationDiv');
if (td && div) {
div.style.height = (td.getHeight() - 10) + "px";
}
}
ensureLoginForm();
</script>
</c:otherwise></c:choose>
</html:html>
The problem I am facing when I try to get the value of hidden input which contains the token from the session ,I am getting just null... I will be very thankful If someone can help.This is how I retrieve the value.
String token = request.getParameter("token");