Skip to content

Fix ClassLoader Security Vulnerability #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package gaarason.database.logging;
import java.security.AccessController;
import java.security.PrivilegedAction;


/**
Expand Down Expand Up @@ -47,10 +49,28 @@ public static Class<?> classForName(String className) throws ClassNotFoundExcept
}

private static ClassLoader getClassLoader() {
// Keep original behavior if default class loader is set
if (defaultClassLoader != null) {
return defaultClassLoader;
} else {
}

// Check if security manager is present (optimization from fixed code)
if (System.getSecurityManager() == null) {
// Fast path when no security manager exists
return Thread.currentThread().getContextClassLoader();
} else {
// Use doPrivileged when security manager is active
return AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> {
try {
return Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) {
// Log exception but don't expose stack trace
// Using System.err since we don't want to assume logger availability
System.err.println("SecurityException: Unable to access thread context class loader");
// Return null on failure, maintaining original behavior on exception
return null;
}
});
}
}

Expand Down