Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

Plan an upgrade of a service from Spring Security 5.8 to 6.x and then 7.x. What steps reduce risk?

First reach 5.8 and apply its migration preparation steps, which expose the 6.0 behaviour changes as opt-in settings we can switch on one at a time while still on 5.8. Then check the main behaviour changes, explicit saving of the SecurityContext, request matching, CSRF token handling with deferred tokens and BREACH protection, and authorization on all dispatcher types, with MockMvc security tests on every endpoint, including error dispatch and static resources. For 7, remove the non-lambda DSL and the deprecated APIs and review new defaults such as path pattern matching against your version's migration guide, and roll out each step behind a canary while watching 401 and 403 rates.

Why this question is asked

A security framework upgrade is risky in a particular way: when it goes wrong, it either locks users out, which is loud, or quietly opens something that was closed, which is worse. Two major versions in a row multiply that risk. Interviewers ask for the plan because a good answer shows a method rather than a list of renames: make changes small, make each behaviour change visible, and prove the result with tests and production signals. In this answer, we will lay out the path, use 5.8's preparation steps, go through the behaviour changes that bite, build the safety net of tests, handle the step to 7, and plan the rollout.

1The Shape of the Plan

The core idea is to never change many things at once. Spring Security 5.8 was released specifically as a bridge: it contains the new APIs and lets us opt into most 6.0 behaviours through settings. So we split the work into small steps, each of which can be tested and deployed on its own.

Step throughUpgrade path, one step at a time
  1. Upgrade to 5.8 (Boot 2.7)No behaviour change yet
  2. Opt into 6.0 behaviours one by oneDeploy each, watch 401 and 403
  3. Move config to new APIs and lambda DSLStill on 5.8
  4. Upgrade to 6.x (Boot 3, Jakarta EE)Mostly a version bump now
  5. Remove deprecations flagged by 6.xPrepare for 7
  6. Upgrade to 7.x (Boot 4)Review new defaults

6 steps in order. Play them, or step through them one at a time.

Each box is a separate, deployable change.

2Using 5.8's Preparation Steps

The migration guide for 6.0 lists each behaviour change with a setting that turns it on in 5.8. We enable them one at a time, deploy, and watch. If something breaks, we know exactly which change caused it, and we can switch it back while we fix the application.

Java
// Spring Security 5.8: opting into 6.0 behaviours early (check the 5.8 migration guide for the full list)
http
.securityContext(c -> c.requireExplicitSave(true)) // 6.0: context is not saved automatically
.authorizeHttpRequests(a -> a
.shouldFilterAllDispatcherTypes(true) // 6.0: forwards and errors are authorized
.requestMatchers("/public/**").permitAll()
.anyRequest().authenticated())
.csrf(c -> c.csrfTokenRequestHandler(new XorCsrfTokenRequestAttributeHandler())); // 6.0 CSRF defaults
@EnableMethodSecurity // replaces @EnableGlobalMethodSecurity

Notice that each of these lines is a deliberate change of behaviour, not a rename. That is why we deploy them separately, ideally a few days apart, instead of in one big commit.

3The Behaviour Changes That Bite

Four changes cause most upgrade incidents. Explicit context saving: code that logs users in by calling setAuthentication() is forgotten on the next request unless it calls securityContextRepository.saveContext(). Request matching: requestMatchers() matches the way Spring MVC routes, which is safer but can change which rule applies to a path such as /admin/ or /admin.json. CSRF token handling: tokens are loaded lazily (deferred) and, by default, masked with a random value on every request to protect against BREACH attacks, which can break single-page applications that read the token from a cookie and send it back raw. Authorization on all dispatcher types: forwards and the error dispatch to /error are now checked, so error pages can turn into 401 or 403 unless they are permitted.

For each change, we know where to look in our own code: manual logins, unusual URL patterns, JavaScript clients that handle CSRF, and custom error pages.

Behaviour changes in 6.0 and what to check
ChangeTypical symptomWhat to check
Explicit save of SecurityContextLogged in for one request onlyCustom login code, test helpers
Request matching follows MVCA rule no longer applies to a pathPatterns with suffixes or trailing slashes
Deferred, masked CSRF tokensSPA gets 403 on every POSTHow the front end reads and sends the token
All dispatcher types authorizedError pages return 401 or 403Permit /error and forward targets

4A Safety Net of Security Tests

Before the first step we write tests that pin down today's security behaviour, so every later step is checked against them. The key is coverage: every endpoint, not just a few. We enumerate the application's handler mappings, so a new endpoint without a rule is caught automatically, and we add the paths people forget: the error page, static resources, actuator endpoints.

Java
@SpringBootTest
@AutoConfigureMockMvc
class SecurityMatrixTest {
@Autowired MockMvc mvc;
@Test void anonymousIsRejectedEverywhereExceptPublic() throws Exception {
mvc.perform(get("/orders")).andExpect(status().isUnauthorized()); // 401
mvc.perform(get("/public/info")).andExpect(status().isOk()); // 200
mvc.perform(get("/css/app.css")).andExpect(status().isOk()); // static resource stays public
}
@Test @WithMockUser(roles = "USER")
void userCannotReachAdmin() throws Exception {
mvc.perform(get("/admin/users")).andExpect(status().isForbidden()); // 403
mvc.perform(post("/orders").with(csrf())).andExpect(status().isCreated()); // CSRF still accepted
}
@Test void errorPageKeepsStatus() throws Exception {
mvc.perform(get("/does-not-exist")).andExpect(status().isNotFound()); // not turned into 401
}
}

Notice the CSRF and error page cases. They are exactly where the 6.0 behaviour changes show up, and they are rarely covered by ordinary functional tests. A single test that lists every mapped URL with its expected status for anonymous, user and admin callers turns the upgrade from hoping into checking.

5The Step to 7

By the time we reach 7, most work is done if we followed the plan, because 7 mainly removes what 6.x deprecated. We remove the non-lambda DSL (and() chaining), replace any remaining deprecated APIs that the 6.x compiler warnings point to, and check new defaults. The one most likely to matter is path pattern matching: requestMatchers() is backed by PathPatternRequestMatcher, so unusual patterns may need changes. Spring Boot 4 also brings Spring Framework 7 and Jakarta EE 11, which have their own migration notes. The exact list differs by minor version, so we read the 7.x migration guide for the version we target, and use OpenRewrite recipes for the mechanical parts.

6Rolling Out Behind a Canary

Tests catch what we thought to test; production catches the rest. Each step goes to a canary first, a small share of traffic such as 5 percent, for at least a day, before full rollout. We compare the canary's 401 and 403 rates, login success rate, CSRF rejections and session creation rate with the rest of the fleet. A jump in 403 on POST requests usually means CSRF; a jump in 401 after login means context saving; a change in session creation means stateless and stateful paths changed. Because each step changes one behaviour, the signal tells us which one to look at.

7Follow-up questions

Why not skip 5.8 and jump straight to 6.x?

Because then the namespace move to Jakarta EE, Spring Boot 3, the API changes and four behaviour changes all land in one deployment. When something breaks, we cannot tell which change caused it, and we cannot switch one off. 5.8 lets us take the behaviour changes one at a time on the old platform.

The single-page application gets 403 on every POST after the upgrade. What do you do?

The front end probably reads the raw token from the XSRF-TOKEN cookie, but 6.0 expects the masked token by default. The documented fix for SPAs is to configure the CSRF request handler for that client pattern; the Spring Security reference has a section on single-page applications, and the exact configuration depends on your version.

How long should a canary run?

Long enough to see the traffic patterns that matter: at least one business day, and for applications with weekly batch or reporting jobs, a full cycle of those. Security regressions often hit rare paths, so time matters more than traffic share.

8Conclusion

In this answer, we planned the upgrade as a series of small, deployable steps. On 5.8, we opted into the 6.0 behaviours one at a time and moved the configuration to the new APIs. We checked the changes that bite, explicit context saving, MVC-style request matching, deferred and masked CSRF tokens and authorization on all dispatcher types, against a full matrix of MockMvc security tests including error dispatch and static resources. For 7, we removed the non-lambda DSL and deprecated APIs and reviewed new defaults such as path pattern matching, and rolled out every step behind a canary while watching 401 and 403 rates.

What to say in the interviewAbout 100 seconds aloud

Open with

My plan is to never change many things at once. Step one is reaching 5.8, which is a bridge release: it has the new APIs and lets me opt into the 6.0 behaviours one by one.

Then, if they want more

Before anything else I write a security test matrix with MockMvc covering every endpoint for anonymous, user and admin, plus the easily forgotten paths: the error page, static resources and actuator, and CSRF on writes. Then on 5.8 I switch on each 6.0 behaviour separately and deploy it.

The ones that bite are explicit saving of the security context, which breaks custom login code; request matching that follows Spring MVC, which can change which rule applies; CSRF tokens that are deferred and masked against BREACH, which often breaks single-page apps; and authorization applying to all dispatcher types, which can turn error pages into 401s.

I also move the configuration to SecurityFilterChain beans, requestMatchers, authorizeHttpRequests and the lambda DSL while still on 5.8, so the jump to 6 with Boot 3 and Jakarta is mostly a version bump.

Then I fix every deprecation 6.x warns about, because 7 mainly removes them, including and() chaining, and I check the 7 migration guide for new defaults like path pattern matching, using OpenRewrite for the mechanical parts.

Every step goes to a canary for at least a day, and I compare 401 and 403 rates, login success, CSRF rejections and session creation with the rest of the fleet.

About this answer

Last updated
12 November 2026
Versions it names
Spring Security 5, Jakarta EE 11, Spring Boot 3, Spring Boot 4
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Security reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Plan an upgrade of a service from Spring Security 5.8 to 6.x and then 7.x. What steps...": https://scrivio-interview-library.netlify.app/spring-boot/security-architecture/abc747966b/