From 51b46f3909ed28baf52112d214fb5086e73cd97e Mon Sep 17 00:00:00 2001 From: Liangjun Song <146005915+adai26@users.noreply.github.com> Date: Fri, 11 Oct 2024 19:42:02 +0800 Subject: [PATCH] Merge pull request #20996 from overleaf/ls-proper-error-for-wrong-git-url-format proper error message for wrong git url format GitOrigin-RevId: a6278850c2eca7e85c2526135d1c769fcbe94729 --- .../ic/wlgitbridge/server/Oauth2Filter.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/Oauth2Filter.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/Oauth2Filter.java index e5abfb328a..5bd3904e47 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/Oauth2Filter.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/Oauth2Filter.java @@ -122,7 +122,7 @@ public class Oauth2Filter implements Filter { cred.setAccessToken(password); } else if (this.isUserPasswordEnabled) { // password auth has been deprecated for git-bridge - handlePasswordAuthenticationDeprecation(projectId, request, response); + handlePasswordAuthenticationDeprecation(projectId, username, request, response); return; } else { handleNeedAuthorization(projectId, username, request, response); @@ -265,14 +265,24 @@ public class Oauth2Filter implements Filter { } private void handlePasswordAuthenticationDeprecation( - String projectId, HttpServletRequest request, HttpServletResponse response) + String projectId, String username, HttpServletRequest request, HttpServletResponse response) throws IOException { - Log.info("[{}] Password authentication deprecated, ip={}", projectId, getClientIp(request)); - sendResponse( - response, - 403, - Arrays.asList( - "Overleaf now only supports Git authentication tokens to access git. See: https://www.overleaf.com/learn/how-to/Git_integration_authentication_tokens")); + if (username.contains("@")) { + Log.info("[{}] Password authentication deprecated, ip={}", projectId, getClientIp(request)); + sendResponse( + response, + 403, + Arrays.asList( + "Overleaf now only supports Git authentication tokens to access git. See: https://www.overleaf.com/learn/how-to/Git_integration_authentication_tokens")); + } else { + Log.info("[{}] Wrong git URL format, ip={}", projectId, getClientIp(request)); + sendResponse( + response, + 403, + Arrays.asList( + "Overleaf now only supports Git authentication tokens to access git. See: https://www.overleaf.com/learn/how-to/Git_integration_authentication_tokens", + "Please make sure your Git URL is correctly formatted. For example: https://git@git.overleaf.com/ or https://git:@git.overleaf.com/")); + } } /*