////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////

[[sessionFixation]]
== Session Fixation Prevention

To guard against https://en.wikipedia.org/wiki/Session_fixation[session-fixation attacks] set the `useSessionFixationPrevention` attribute to `true`:

[source,groovy]
----
grails.plugin.springsecurity.useSessionFixationPrevention = true
----

Upon successful authentication a new HTTP session is created and the previous session's attributes are copied into it. If you start your session by clicking a link that was generated by someone trying to hack your account, which contained an active session id, you are no longer sharing the previous session after login. You have your own session.

Session fixation is less of a problem now that Grails by default does not include jsessionid in URLs (see https://jira.grails.org/browse/GRAILS-3364[this JIRA issue]), but it's still a good idea to use this feature.

Note that there is an issue when using the https://grails.org/plugin/cookie-session[cookie-session] plugin; see https://github.com/benlucchesi/grails-cookie-session-v2/issues/17[this issue] for more details.

The table shows configuration options for session fixation.

.Session Fixation Prevention configuration options
[cols="30,30,40"]
|====================
| *Property* | *Default Value* | *Meaning*

|useSessionFixationPrevention
|`true`
|Whether to use session fixation prevention

|sessionFixationPrevention.migrate
|`true`
|Whether to copy the session attributes of the existing session to the new session after login

|sessionFixationPrevention.alwaysCreateSession
|`false`
|Whether to always create a session even if one did not exist at the start of the request
|====================
