Skip to content

Add CookieHttpSessionStrategy.setCookieValueDelimiter #615

Closed

Description

@rwinch

Currently the session alias and the session id's are always delimited by " ". It would be nice to allow users to inject their own delimiter to work around issues caused by Tomcat 8.5 using RFC-6265 (i.e. #605)

Example Usage

This demonstrates how to migrate from a delimiter of " " to a new delimiter of "_" which is compliant with RFC 6265 and still read old cookie values.

@Bean
public CookieHttpSessionStrategy strategy() {
    CookieHttpSessionStrategy strategy = new CookieHttpSessionStrategy();
    strategy.setDeserializationDelimiter("_ ");
    strategy.setSerializationDelimiter("_");
    return strategy;
}

// necessary to ensure you can still read the value if using Tomcat 8.5
@Bean
public EmbeddedServletContainerCustomizer customizer() {
    return container -> {
        if (container instanceof TomcatEmbeddedServletContainerFactory) {
            TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
            tomcat.addContextCustomizers(context -> context.setCookieProcessor(new LegacyCookieProcessor()));
        }
    };
}

Users should:

  • Have the above code deployed for at least the length of time a session is valid. This will ensure that all new sessions are created with the new delimiter and are parsed with both the old delimiter and the new delimiter
  • Ensure that something (i.e. a servlet Filter) rewrites existing cookies with the new delimiter. This is necessary because Spring Session only writes new sessions as a Cookie, so the configuration only ensures new sessions are correct.
  • Afterwards, all sessions should be in the new format, so the customization to Tomcat can be removed

Activity

  1. added this to the milestone on Sep 6, 2016
  2. self-assigned this
    on Sep 6, 2016
  3. added a commit that references this issue on Sep 7, 2016
    b79dc79
  4. added a commit that references this issue on Jan 20, 2025
    61492c4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions