You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by "nscendoni (via GitHub)" <gi...@apache.org> on 2025/11/24 13:08:05 UTC
[PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
nscendoni opened a new pull request, #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38
This commit contains also the fix for:
SLING-13004 Query parameters from original request are lost after authentication
--
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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38#issuecomment-3572010608
## [](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38) **Quality Gate failed**
Failed conditions
 [B Maintainability Rating on New Code](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38) (required ≥ A)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
Posted by "nscendoni (via GitHub)" <gi...@apache.org>.
nscendoni merged PR #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38
--
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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38#issuecomment-3581215975
## [](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38) **Quality Gate failed**
Failed conditions
 [B Maintainability Rating on New Code](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38) (required ≥ A)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
Posted by "nscendoni (via GitHub)" <gi...@apache.org>.
nscendoni commented on code in PR #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38#discussion_r2567683605
##########
src/main/java/org/apache/sling/auth/oauth_client/impl/OidcAuthenticationHandler.java:
##########
@@ -493,18 +493,34 @@ public boolean requestCredentials(@NotNull HttpServletRequest request, @NotNull
} catch (IOException e) {
logger.error("Error while redirecting to default redirect: {}", e.getMessage(), e);
throw new RuntimeException(e);
+ } catch (OAuthEntryPointException e) {
+ logger.warn("Invalid uri to redirect after login:: {}", e.getMessage(), e);
+ throw new RuntimeException(e);
}
}
private @NotNull RedirectTarget getAuthenticationRequestUri(
- @NotNull ClientConnection connection, @NotNull HttpServletRequest request, @NotNull URI callbackUri) {
+ @NotNull ClientConnection connection, @NotNull HttpServletRequest request, @NotNull URI callbackUri)
+ throws OAuthEntryPointException {
ResolvedConnection conn = ResolvedOidcConnection.resolve(connection);
// The client ID provisioned by the OpenID provider when
// the client was registered is stored in the connection.
- String redirect = request.getRequestURI();
+ // Read if there is a parameter to the url where we need to redirect the user after authentication
+ String redirect = request.getParameter(RedirectHelper.PARAMETER_NAME_OIDC_REDIRECT);
Review Comment:
Fixed.
--
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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
Posted by "rombert (via GitHub)" <gi...@apache.org>.
rombert commented on PR #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38#issuecomment-3575346765
> Thanks for updating the PR. Overall looks good, see inline for a couple of comments.
Additionally, the test notes from https://sonarcloud.io/project/issues?issueStatuses=OPEN%2CCONFIRMED&sinceLeakPeriod=true&pullRequest=38&id=apache_sling-org-apache-sling-auth-oauth-client would be good to fix.
The exception handling is already mentioned in initial 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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
Posted by "nscendoni (via GitHub)" <gi...@apache.org>.
nscendoni commented on PR #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38#issuecomment-3584836824
I also had to fix a flaky integration test that caused the pipeline to fail. I applied the same workaround we previously used for other flaky IT tests.
--
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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
Posted by "rombert (via GitHub)" <gi...@apache.org>.
rombert commented on code in PR #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38#discussion_r2559460014
##########
src/test/java/org/apache/sling/auth/oauth_client/impl/RedirectHelperTest.java:
##########
@@ -85,4 +85,64 @@ void testFindLongestPathMatchingWithSibling() {
String result = RedirectHelper.findLongestPathMatching(paths, url);
assertEquals("/a/b", result);
}
+
Review Comment:
These tests look very good, thank you for the comprehensive coverage. Would it make sense to add a test to prove that protocol-relative URLs ( e.g. `//evil.com` ) are rejected?
##########
src/main/java/org/apache/sling/auth/oauth_client/impl/OidcAuthenticationHandler.java:
##########
@@ -493,18 +493,34 @@ public boolean requestCredentials(@NotNull HttpServletRequest request, @NotNull
} catch (IOException e) {
logger.error("Error while redirecting to default redirect: {}", e.getMessage(), e);
throw new RuntimeException(e);
+ } catch (OAuthEntryPointException e) {
+ logger.warn("Invalid uri to redirect after login:: {}", e.getMessage(), e);
+ throw new RuntimeException(e);
}
}
private @NotNull RedirectTarget getAuthenticationRequestUri(
- @NotNull ClientConnection connection, @NotNull HttpServletRequest request, @NotNull URI callbackUri) {
+ @NotNull ClientConnection connection, @NotNull HttpServletRequest request, @NotNull URI callbackUri)
+ throws OAuthEntryPointException {
ResolvedConnection conn = ResolvedOidcConnection.resolve(connection);
// The client ID provisioned by the OpenID provider when
// the client was registered is stored in the connection.
- String redirect = request.getRequestURI();
+ // Read if there is a parameter to the url where we need to redirect the user after authentication
+ String redirect = request.getParameter(RedirectHelper.PARAMETER_NAME_OIDC_REDIRECT);
Review Comment:
Why did you add a new parameter ? We already have `RedirectHelper.PARAMETER_NAME_REDIRECT` for the OAuth 2.x flow.
##########
src/main/java/org/apache/sling/auth/oauth_client/impl/RedirectHelper.java:
##########
@@ -144,4 +145,16 @@ private static boolean isDescendantOrEqual(String path, String descendant) {
return descendant.startsWith(pattern);
}
}
+
+ public static void validateRedirect(String redirect) throws OAuthEntryPointException {
+ // Validate that it is not a cross-site redirect
+ if (redirect == null || redirect.isEmpty()) {
+ return;
+ }
+ if (!redirect.startsWith("/")) {
+ String message = "Invalid redirect URL: " + redirect;
+ // Relative redirect within the same domain is allowed
+ throw new OAuthEntryPointException(message, new IllegalArgumentException(message));
Review Comment:
I am not sure why we wrap this in an OauthEntryPointException, only to unwrap it and throw it as a runtime one.
I think it's good to hide the specific messages from the end user but we could do it in a more expressive way. The way we did this so far in the `OAuthCallbackServlet` and `OAuthEntryPointServlet` is to catch all errors and wrap then in a subclass of `OAuthFlowException` with a generic message.
Would that work in this case as well?
--
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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38#issuecomment-3575021503
## [](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38) **Quality Gate failed**
Failed conditions
 [B Maintainability Rating on New Code](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38) (required ≥ A)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38#issuecomment-3584812041
## [](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [90.9% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38)
--
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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
Posted by "nscendoni (via GitHub)" <gi...@apache.org>.
nscendoni commented on code in PR #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38#discussion_r2567686262
##########
src/main/java/org/apache/sling/auth/oauth_client/impl/RedirectHelper.java:
##########
@@ -144,4 +145,16 @@ private static boolean isDescendantOrEqual(String path, String descendant) {
return descendant.startsWith(pattern);
}
}
+
+ public static void validateRedirect(String redirect) throws OAuthEntryPointException {
+ // Validate that it is not a cross-site redirect
+ if (redirect == null || redirect.isEmpty()) {
+ return;
+ }
+ if (!redirect.startsWith("/")) {
+ String message = "Invalid redirect URL: " + redirect;
+ // Relative redirect within the same domain is allowed
+ throw new OAuthEntryPointException(message, new IllegalArgumentException(message));
Review Comment:
I did a small refactoring on exception handling in OidcAuthenticationHandler.
--
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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
Posted by "nscendoni (via GitHub)" <gi...@apache.org>.
nscendoni commented on code in PR #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38#discussion_r2567682551
##########
src/test/java/org/apache/sling/auth/oauth_client/impl/RedirectHelperTest.java:
##########
@@ -85,4 +85,64 @@ void testFindLongestPathMatchingWithSibling() {
String result = RedirectHelper.findLongestPathMatching(paths, url);
assertEquals("/a/b", result);
}
+
Review Comment:
Thanks for the catch. I've added this test, and patched the 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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
Posted by "rombert (via GitHub)" <gi...@apache.org>.
rombert commented on PR #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38#issuecomment-3586461461
Thanks @nscendoni . It's not clear to me if you're done with the changes or not, please re-request a review when ready.
--
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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38#issuecomment-3570756645
## [](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38) **Quality Gate passed**
Issues
 [9 New issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [93.5% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-auth-oauth-client&pullRequest=38)
--
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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] SLING-12993 Support oidc_request_path Parameter in OIDC Authentication Handler [sling-org-apache-sling-auth-oauth-client]
Posted by "nscendoni (via GitHub)" <gi...@apache.org>.
nscendoni commented on PR #38:
URL: https://github.com/apache/sling-org-apache-sling-auth-oauth-client/pull/38#issuecomment-3571974935
> Thanks for the PR. I think it would be better to have one PR for fix, it makes it easier to review and track for git blame, revert, etc.
I understand. I removed the fix for SLING-13004 and his test
--
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: commits-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org