Repository navigation
fix(security): accept a role hierarchy written without spaces around the > operator - #16969
borinquenkid wants to merge 5 commits into
Conversation
…the > operator Spring Security splits a hierarchy line only where the > operator has whitespace on each side, and ignores a line such as ROLE_ADMIN>ROLE_USER without a message, so a user got no role from it. Grails 3 accepted that form. The plugin now writes each line with one space on each side of the operator before it hands the hierarchy to the roleHierarchy bean. RoleHierarchyNormalizerSpec runs the form through RoleHierarchyImpl.fromHierarchy and checks the roles that are reachable, and the page of hierarchical roles in the guide says the spaces are optional. Fixes #15892 Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
jamesfredley
left a comment
There was a problem hiding this comment.
Not approving. A hierarchy written with repeated > operators is rewritten into a chain that grants the lower role.
…tten Answers the review of #16969: ROLE_ADMIN>>>ROLE_USER was rewritten to ROLE_ADMIN > > > ROLE_USER, which Spring Security reads with the operator as a role, so ROLE_ADMIN could reach ROLE_USER. A line is rewritten only when every piece is a role; a line with an empty piece (repeated, leading or trailing operator) stays as written and grants nothing, as before the rewrite. The spec tries each line shape through RoleHierarchyImpl. RoleHierarchyNormalizer is package-private: it is used only by the plugin, and a public class is new API that a patch release does not add. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
Answers the I did not drop the empty pieces as the comment suggests:
Not tried: a role name that itself contains whitespace. |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A line with an empty piece is left as written, and a line without spaces still parses. A hierarchy loaded from the database loses those roles when it is reloaded.
… startup reloadDBRoleHierarchy assigned the stored lines to the role hierarchy as written, while startup reads them through the normalizer that puts one space on each side of the operator. A stored line such as ROLE_ADMIN>ROLE_USER, without spaces, then granted ROLE_USER at startup and lost it after a reload. The reload path reads the stored lines through the same normalizer. SpringSecurityServiceRoleHierarchySpec reloads lines with and without spaces, a chain of three roles, two lines, and lines with an empty piece, which are left as written, and compares the roles each reaches with the hierarchy built at startup. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
Thank you, that is the reload path I missed. Startup reads the stored hierarchy through the normalizer, and The reload path now reads the stored lines through the same normalizer, so the two cannot disagree. I searched for any other place that assigns the hierarchy: startup and reload are the only two.
|
jamesfredley
left a comment
There was a problem hiding this comment.
The items this review found have been addressed. A reloaded hierarchy is read the same way as at startup, and a line with an empty piece is left as written.
The 7.0.x patch line takes no more fixes after the 2026-11-25 releases; this PR moves to 7.2.x. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
Moved to 7.2.x: after the 2026-11-25 releases the 7.x line takes fixes on 7.2.x only. The branch has 7.2.x merged in and its module tests and codeStyle pass on it. Nothing else changed, so the review so far still applies; a fresh approval on the new head is needed for the merge rule. |
sbglasius
left a comment
There was a problem hiding this comment.
This is an AI assisted review
Fix looks right, and startup and reload now read the hierarchy the same way. LGTM with one note inline.
| } | ||
|
|
||
| applicationContext.roleHierarchy.hierarchy = roleHierarchy | ||
| applicationContext.roleHierarchy.hierarchy = RoleHierarchyNormalizer.normalize(roleHierarchy) |
There was a problem hiding this comment.
Existing A>B lines that were silently ignored will start granting roles on upgrade. Worth a short note in upgrading72x.adoc, since it widens effective authorization.
…around > A line such as ROLE_ADMIN>ROLE_USER, which Spring Security ignored before, now grants its roles, so the effective authorization of an upgraded application can widen (review on #16969). Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
@sbglasius Good point, thanks. I added the note in 8c375fb, in a new Grails 7.2.6 section of the upgrade guide ( It says that a line such as |
✅ All tests passed ✅Test SummaryTip Inspect all details with the TestLens CLI: CI / Functional Tests (Java 17, indy=true) > :grails-test-examples-datasources:integrationTest
🏷️ Commit: 8c375fb Test FailuresOsivRequestSessionSpec > a task a request returns lazily loads associations of the entities its action loaded (:grails-test-examples-datasources:integrationTest in CI / Functional Tests (Java 17, indy=true) | Attempt 1/2)Learn more about TestLens at testlens.app/docs. |
Fixes #15892 (reported by fjloma; a merge to 7.0.x does not close it, so it is closed by hand once the merge-ups land).
grails.plugin.springsecurity.roleHierarchy = 'ROLE_ADMIN>ROLE_USER'gave the user no extra role and no message, as the issue says. The cause is in Spring Security, not in the plugin: it splits a hierarchy line only where the>operator has whitespace on each side, and ignores a line without. I checked it directly against Spring Security 6.5.11 (setHierarchyandfromHierarchy) and 7.2.0-M2 (fromHierarchy):ROLE_ADMIN>ROLE_USERreaches[ROLE_ADMIN], andROLE_ADMIN > ROLE_USERreaches[ROLE_USER, ROLE_ADMIN]. Grails 3, on an older Spring Security, accepted the form without spaces.Change: a small
RoleHierarchyNormalizerwrites each line with one space on each side of every>(trimming, dropping blank lines, accepting\r\n), and the plugin applies it where it assigns the hierarchy to theroleHierarchybean. The line inSpringSecurityCoreGrailsPluginis the one assignment site, for theroleHierarchysetting and for the persistent hierarchy alike. The page of hierarchical roles in the guide now says the spaces are optional. I did not add a warning for a line without>: I did not confirm what Spring does with one, and accepting the syntax removes the surprise the issue is about.Tests:
RoleHierarchyNormalizerSpec(14 rows) feeds the normalized form toRoleHierarchyImpl.fromHierarchyand checks the reachable roles (no spaces, one-sided spaces, a multiline block, two chained lines, Windows line ends), the normalized text, and thatnulland an empty string stay as they are. Without the class the spec fails, as run in the repo. All 187 tests of the plugin pass; CodeNarc, Checkstyle and rat are clean. CI is off (no ci).Not covered: a running application (the spec exercises the form and Spring's parser, not the bean wiring), and 8.0.x, where
MutableRoleHierarchyreplaced the bean: the same assignment line is merged up there and the class works with it, to be confirmed at the merge-up.Two of the three reviewers (matrei, codeconsole, jdaugherty), as 7.0.x is released.
https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL