Skip to content

Commit d635d8f

Browse files
Copilotcoopernetes
andcommitted
Fix code review issues: consistent logging, Base64 validation, extract magic numbers
Co-authored-by: coopernetes <57812123+coopernetes@users.noreply.github.com>
1 parent 5c3b6fe commit d635d8f

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

jgit-proxy-core/src/main/java/org/finos/gitproxy/git/LocalRepositoryCache.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020
@Slf4j
2121
public class LocalRepositoryCache {
2222

23+
private static final int DEFAULT_CLONE_DEPTH = 100;
24+
2325
private final Path cacheDirectory;
2426
private final Map<String, CachedRepository> cache = new ConcurrentHashMap<>();
2527
private final int cloneDepth;
2628
private final boolean registerShutdownHook;
2729

2830
/** Default constructor that uses system temp directory with shutdown hook. */
2931
public LocalRepositoryCache() throws IOException {
30-
this(Files.createTempDirectory("jgit-proxy-cache-"), 100, true);
32+
this(Files.createTempDirectory("jgit-proxy-cache-"), DEFAULT_CLONE_DEPTH, true);
3133
}
3234

3335
/**
@@ -37,7 +39,7 @@ public LocalRepositoryCache() throws IOException {
3739
* @param registerShutdownHook Whether to register shutdown hook (false for Spring apps)
3840
*/
3941
public LocalRepositoryCache(Path cacheDirectory, boolean registerShutdownHook) throws IOException {
40-
this(cacheDirectory, 100, registerShutdownHook);
42+
this(cacheDirectory, DEFAULT_CLONE_DEPTH, registerShutdownHook);
4143
}
4244

4345
/**

jgit-proxy-core/src/main/java/org/finos/gitproxy/git/TemporaryRepositoryResolver.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,17 @@ private String extractRemoteUrl(HttpServletRequest req, String name) {
5252
String authCredentials = "";
5353

5454
if (authHeader != null && authHeader.startsWith("Basic ")) {
55-
// Extract credentials from Basic auth
56-
String base64Credentials = authHeader.substring("Basic ".length()).trim();
57-
String credentials = new String(java.util.Base64.getDecoder().decode(base64Credentials));
58-
// credentials format is "username:password"
59-
authCredentials = credentials + "@";
55+
try {
56+
// Extract credentials from Basic auth
57+
String base64Credentials =
58+
authHeader.substring("Basic ".length()).trim();
59+
String credentials = new String(java.util.Base64.getDecoder().decode(base64Credentials));
60+
// credentials format is "username:password"
61+
authCredentials = credentials + "@";
62+
} catch (IllegalArgumentException e) {
63+
log.warn("Invalid Base64 encoding in Authorization header", e);
64+
// Continue without auth credentials
65+
}
6066
}
6167

6268
// This is a simplified implementation

jgit-proxy-core/src/main/java/org/finos/gitproxy/servlet/filter/CheckUserPushPermissionFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public CheckUserPushPermissionFilter(UserAuthorizationService userAuthorizationS
3030
public void doHttpFilter(HttpServletRequest request, HttpServletResponse response) throws IOException {
3131
var requestDetails = (GitRequestDetails) request.getAttribute(GIT_REQUEST_ATTRIBUTE);
3232
if (requestDetails == null) {
33-
log.warn("GitRequestDetails not found in request details");
33+
log.warn("GitRequestDetails not found in request attributes");
3434
return;
3535
}
3636

0 commit comments

Comments
 (0)