You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "rishabhdaim (via GitHub)" <gi...@apache.org> on 2026/09/17 11:49:27 UTC
[PR] SLING-13353 : prevent unbounded handleLoginFailure/getAnonymousResolver recursion on repeated anonymous login failure [sling-org-apache-sling-auth-core]
rishabhdaim opened a new pull request, #29:
URL: https://github.com/apache/sling-org-apache-sling-auth-core/pull/29
## Summary
`SlingAuthenticator` recurses without bound between `handleLoginFailure` and `getAnonymousResolver` when acquiring the anonymous `ResourceResolver` keeps failing with `LoginException` (e.g. the backing repository is unavailable). The stack grows until `StackOverflowError`, and since each failed request logs the full repeating trace, a sustained failure floods the error log — in the field this grew until the disk filled.
The two methods call each other with no termination guard:
- `getAnonymousResolver`: on `LoginException` from `getResourceResolver`, calls `handleLoginFailure`;
- `handleLoginFailure`: for a `LoginException` with anonymous access still allowed, calls `getAnonymousResolver`.
So `getAnonymousResolver → handleLoginFailure → getAnonymousResolver → …` repeats as long as the anonymous login keeps failing.
## Changes
- **Fix** (`SlingAuthenticator`): a per-request re-entrancy guard. `getAnonymousResolver` marks (via a request attribute) that anonymous resolution has been attempted; `handleLoginFailure` only falls back to `getAnonymousResolver` when the mark is absent. The anonymous fallback runs at most once per request and terminates normally on repeated failure. All currently-successful paths (including a single legitimate anonymous fallback after a primary-auth failure) are unchanged.
- **Test** (`SlingAuthenticatorAnonymousRecursionTest`): drives `getAnonymousResolver` with a `ResourceResolverFactory` that always throws `LoginException` and asserts no `StackOverflowError` and exactly one `getResourceResolver` call. Without the guard it fails with `StackOverflowError` (thousands of recursive calls); with the guard it passes.
## Test Plan
- [x] New regression test fails without the fix (StackOverflowError, ~3299 recursive calls), passes with it
- [x] Full module test suite green (127 tests)
- [x] `spotless:check` clean
## Links
- JIRA: https://issues.apache.org/jira/browse/SLING-13353
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-13353 : prevent unbounded handleLoginFailure/getAnonymousResolver recursion on repeated anonymous login failure [sling-org-apache-sling-auth-core]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #29:
URL: https://github.com/apache/sling-org-apache-sling-auth-core/pull/29#issuecomment-5713895520
## [](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-core&pullRequest=29) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-core&pullRequest=29)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-13353 : prevent unbounded handleLoginFailure/getAnonymousResolver recursion on repeated anonymous login failure [sling-org-apache-sling-auth-core]
Posted by "anchela (via GitHub)" <gi...@apache.org>.
anchela commented on code in PR #29:
URL: https://github.com/apache/sling-org-apache-sling-auth-core/pull/29#discussion_r4104730155
##########
src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java:
##########
@@ -992,6 +1007,7 @@ private boolean handleLoginFailure(
} else if (reason instanceof LoginException) {
log.info("handleLoginFailure: Unable to authenticate {}: {}", user, reason.getMessage());
if (isAnonAllowed(request)
+ && request.getAttribute(REQUEST_ATTRIBUTE_ANONYMOUS_RESOLVER_ATTEMPTED) == null
Review Comment:
while this works it looks a bit strange. if someone would set the REQUEST_ATTRIBUTE_ANONYMOUS_RESOLVER_ATTEMPTED to Boolean.FALSE it would also pass because the object is not null but still it was slightly counter intuitive. it's not a problem today but something that may end up being either broken or not properly understood (or leading to misunderstanding) in the future.
wdyt?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-13353 : prevent unbounded handleLoginFailure/getAnonymousResolver recursion on repeated anonymous login failure [sling-org-apache-sling-auth-core]
Posted by "anchela (via GitHub)" <gi...@apache.org>.
anchela commented on code in PR #29:
URL: https://github.com/apache/sling-org-apache-sling-auth-core/pull/29#discussion_r4104730155
##########
src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java:
##########
@@ -992,6 +1007,7 @@ private boolean handleLoginFailure(
} else if (reason instanceof LoginException) {
log.info("handleLoginFailure: Unable to authenticate {}: {}", user, reason.getMessage());
if (isAnonAllowed(request)
+ && request.getAttribute(REQUEST_ATTRIBUTE_ANONYMOUS_RESOLVER_ATTEMPTED) == null
Review Comment:
while this works it looks a bit strange. if someone would set the REQUEST_ATTRIBUTE_ANONYMOUS_RESOLVER_ATTEMPTED to Boolean.FALSE it would also pass because the object is not null but still it was slightly counter intuitive. it's not a problem today but something that may end up being either broken or not properly understood (or leading to misunderstanding) in the future.
wdyt?
btw: this might actually be a nice test case to add to illustrate the intention irrespective on how you decide to deal with the comment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-13353 : prevent unbounded handleLoginFailure/getAnonymousResolver recursion on repeated anonymous login failure [sling-org-apache-sling-auth-core]
Posted by "anchela (via GitHub)" <gi...@apache.org>.
anchela merged PR #29:
URL: https://github.com/apache/sling-org-apache-sling-auth-core/pull/29
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-13353 : prevent unbounded handleLoginFailure/getAnonymousResolver recursion on repeated anonymous login failure [sling-org-apache-sling-auth-core]
Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim commented on PR #29:
URL: https://github.com/apache/sling-org-apache-sling-auth-core/pull/29#issuecomment-5871677679
> hi @rishabhdaim , thanks for the heads up. i had another quick look and my comments is addressed. thank you.
>
> one thing that came to my mind: i vaguely remember that we attempted to fix that before. i might be mistaken and it was a different but similar sounding issue. anyway, my point is: maybe have a quick check to see if there is with this fix some dead code in the sling auth part that needs a cleanup aka some love.
@anchela thanks for the quick review.
I looked through the history and found an older `stackGuard` fix in `AuthenticationInfo`, but that handles a different recursion issue in the read-only map wrapper.
The other existing checks are also for separate login flows, so I don’t see anything from this PR that’s redundant or should be removed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-13353 : prevent unbounded handleLoginFailure/getAnonymousResolver recursion on repeated anonymous login failure [sling-org-apache-sling-auth-core]
Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim commented on code in PR #29:
URL: https://github.com/apache/sling-org-apache-sling-auth-core/pull/29#discussion_r4112132101
##########
src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java:
##########
@@ -992,6 +1007,7 @@ private boolean handleLoginFailure(
} else if (reason instanceof LoginException) {
log.info("handleLoginFailure: Unable to authenticate {}: {}", user, reason.getMessage());
if (isAnonAllowed(request)
+ && request.getAttribute(REQUEST_ATTRIBUTE_ANONYMOUS_RESOLVER_ATTEMPTED) == null
Review Comment:
thanks @anchela for the review, it has been addressed in https://github.com/apache/sling-org-apache-sling-auth-core/pull/29/commits/b8aa904ec09f73a4cac79c4d998edb9c46f28de2
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-13353 : prevent unbounded handleLoginFailure/getAnonymousResolver recursion on repeated anonymous login failure [sling-org-apache-sling-auth-core]
Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim commented on PR #29:
URL: https://github.com/apache/sling-org-apache-sling-auth-core/pull/29#issuecomment-5813426490
@anchela could you please review the PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-13353 : prevent unbounded handleLoginFailure/getAnonymousResolver recursion on repeated anonymous login failure [sling-org-apache-sling-auth-core]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #29:
URL: https://github.com/apache/sling-org-apache-sling-auth-core/pull/29#issuecomment-5848269880
## [](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-core&pullRequest=29) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-core&pullRequest=29)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-13353 : prevent unbounded handleLoginFailure/getAnonymousResolver recursion on repeated anonymous login failure [sling-org-apache-sling-auth-core]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #29:
URL: https://github.com/apache/sling-org-apache-sling-auth-core/pull/29#issuecomment-5843989183
## [](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-core&pullRequest=29) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-auth-core&pullRequest=29&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-core&pullRequest=29)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-13353 : prevent unbounded handleLoginFailure/getAnonymousResolver recursion on repeated anonymous login failure [sling-org-apache-sling-auth-core]
Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim commented on PR #29:
URL: https://github.com/apache/sling-org-apache-sling-auth-core/pull/29#issuecomment-6033932717
## AI-reviewed assessment
*Disclaimer: This comment was prepared with AI assistance and should be confirmed by the project maintainers.*
I reviewed the [MAIA review](https://github.com/apache/sling-org-apache-sling-auth-core/pull/29#pullrequestreview-5439354322) against the merged implementation.
### Medium finding — marker lifetime
I could not validate this as a concrete issue in the supported authentication flow. `handleSecurity()` returns early when a resolver is already attached to the request, and successful anonymous resolution stores that resolver on the request. I found no in-repository path where a normal include or forward reaches `handleLoginFailure()` again after successful resolution.
The concern remains a theoretical edge case if a caller re-enters authentication after removing the resolver attribute. I do not recommend a production change for the merged PR without an integration test reproducing that lifecycle.
### Low finding — test structure
This is a valid optional test-quality suggestion. The regression test uses private reflection, consistent with existing tests, and verifies the key failure mode: one anonymous login attempt with no recursion. It could be strengthened by asserting the terminal error or login-response behavior, but this is not a production defect.
### Verification
The targeted tests passed 40/40 on Java 17; the full suite had previously passed 304 tests. Repository history also showed no earlier fix for this exact recursion; the older `ReadOnlyAuthenticationInfo.stackGuard` addresses a separate issue.
No corrective action is required based on this review. A follow-up integration test could be added if the project wants to validate re-entry after resolver cleanup.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org