Spring option create-session="never" is ignored in some scenarios? -
for web services want disable use of sessions. added create-session="never" config:
<beans:bean id="http403entrypoint" class="org.springframework.security.web.authentication.http403forbiddenentrypoint"/> <http use-expressions="true" entry-point-ref="http403entrypoint" create-session="never"> <custom-filter ref="x509filter" position="pre_auth_filter"/> </http>
this works cases, except when pre-authenticated user has client certificate not registered in application, our authenticationuserdetailsservice throws usernamenotfoundexception. if user has no certificate or has registered certificate, no session created (no set-cookie header in http response). in described case cookie sent. (the cookie respectively session) evaluated on each following request, if client certificate changed (basically allowing session fixation attack - app uses saved authentication instead of re-authenticating on each call).
we use spring security 3.0.5. tested tomcat 6 , 7 , jboss 7.1.1.
why session created in described scenario?
ps: session fixation problem can workarounded setting checkforprincipalchanges in abstractpreauthenticatedprocessingfilter, interested in answer why session created @ all.
the culprit https://jira.spring.io/browse/sec-1476 :
in case of unauthorized access following method in class abstractpreauthenticatedprocessingfilter create session , store exception there:
protected void unsuccessfulauthentication(httpservletrequest request, httpservletresponse response, authenticationexception failed) { securitycontextholder.clearcontext(); if (logger.isdebugenabled()) { logger.debug("cleared security context due exception", failed); } request.getsession().setattribute(webattributes.authentication_exception, failed); }
in fix changed last line, removed getsession() call authenticationexception stored in request.
to fix our project created new class extends x509authenticationfilter , there overrode method unsuccessfulauthentication same content except removed getsession() call.
Comments
Post a Comment