What are the security considerations when using @SessionAttributes and @CookieValue annotations?

@SessionAttributes and @CookieValue both move state outside a single request, which introduces security concerns around what data gets stored there and how it can be tampered with or intercepted.

Key Points

Example

Storing a user's cart contents with @SessionAttributes is reasonable, but storing an authentication flag there instead of relying on Spring Security's session management would create an easy target for session fixation or tampering.

Interview Tip

A concise interview answer is

With @SessionAttributes I'm careful not to store sensitive data in the session unnecessarily, and I make sure sessions are invalidated on logout to prevent fixation attacks. With @CookieValue I treat the value as untrusted client input, validate it, and rely on HttpOnly, Secure, and SameSite flags on any cookie carrying sensitive state.

Last updated: 16 July 2026

Previous question: How do you use the @SessionAttributes and @CookieValue annotations in Spring MVC?

Next question: How do you test Spring MVC applications?

More Spring MVC (Optional) interview questions

All Spring MVC (Optional) questions