-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Restrict LDAP access via JNDI #608
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
package org.apache.logging.log4j.core.util; | ||
|
||
import java.io.File; | ||
import java.net.Inet4Address; | ||
import java.net.Inet6Address; | ||
import java.net.InetAddress; | ||
import java.net.MalformedURLException; | ||
import java.net.NetworkInterface; | ||
|
@@ -25,11 +27,14 @@ | |
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.net.UnknownHostException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Enumeration; | ||
import java.util.List; | ||
|
||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.status.StatusLogger; | ||
import org.apache.logging.log4j.util.Strings; | ||
|
||
/** | ||
* Networking-related convenience methods. | ||
|
@@ -79,6 +84,49 @@ public static String getLocalHostname() { | |
} | ||
} | ||
|
||
/** | ||
* Returns all the local host names and ip addresses. | ||
* @return The local host names and ip addresses. | ||
*/ | ||
public static List<String> getLocalIps() { | ||
List<String> localIps = new ArrayList<>(); | ||
localIps.add("localhost"); | ||
localIps.add("127.0.0.1"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps IPv6 as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could have but this pre-seeding really isn't necessary as they show up in the while loop anyway. |
||
try { | ||
final InetAddress addr = Inet4Address.getLocalHost(); | ||
setHostName(addr, localIps); | ||
} catch (final UnknownHostException ex) { | ||
// Ignore this. | ||
} | ||
try { | ||
final Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); | ||
if (interfaces != null) { | ||
while (interfaces.hasMoreElements()) { | ||
final NetworkInterface nic = interfaces.nextElement(); | ||
final Enumeration<InetAddress> addresses = nic.getInetAddresses(); | ||
while (addresses.hasMoreElements()) { | ||
final InetAddress address = addresses.nextElement(); | ||
setHostName(address, localIps); | ||
} | ||
} | ||
} | ||
} catch (final SocketException se) { | ||
// ignore. | ||
} | ||
return localIps; | ||
} | ||
|
||
private static void setHostName(InetAddress address, List<String> localIps) { | ||
String[] parts = address.toString().split("\\s*/\\s*"); | ||
if (parts.length > 0) { | ||
for (String part : parts) { | ||
if (Strings.isNotBlank(part) && !localIps.contains(part)) { | ||
localIps.add(part); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Returns the local network interface's MAC address if possible. The local network interface is defined here as | ||
* the {@link java.net.NetworkInterface} that is both up and not a loopback interface. | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||||||
/* | ||||||||||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||||||||||
* contributor license agreements. See the NOTICE file distributed with | ||||||||||
* this work for additional information regarding copyright ownership. | ||||||||||
* The ASF licenses this file to You under the Apache license, Version 2.0 | ||||||||||
* (the "License"); you may not use this file except in compliance with | ||||||||||
* the License. You may obtain a copy of the License at | ||||||||||
* | ||||||||||
* http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||
* | ||||||||||
* Unless required by applicable law or agreed to in writing, software | ||||||||||
* distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||
* See the license for the specific language governing permissions and | ||||||||||
* limitations under the license. | ||||||||||
*/ | ||||||||||
package org.apache.logging.log4j.core.lookup; | ||||||||||
|
||||||||||
import javax.naming.Context; | ||||||||||
import javax.naming.Name; | ||||||||||
import javax.naming.spi.ObjectFactory; | ||||||||||
import java.util.Hashtable; | ||||||||||
|
||||||||||
import static org.junit.jupiter.api.Assertions.fail; | ||||||||||
|
||||||||||
/** | ||||||||||
* Test LDAP object | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
*/ | ||||||||||
public class JndiExploit implements ObjectFactory { | ||||||||||
@Override | ||||||||||
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) | ||||||||||
throws Exception { | ||||||||||
fail("getObjectInstance must not be allowed"); | ||||||||||
return null; | ||||||||||
} | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this reference
allowedJndiProtocols
as well?