Skip to content

Commit fb0def6

Browse files
committed
[CVE-2020-1729] Ensure utility methods wrapping doPrivileged calls are not publicly available.
Additionally a doPrivileged is not necessary if no SecurityManager is installed.
1 parent 4e7ea86 commit fb0def6

File tree

3 files changed

+65
-12
lines changed

3 files changed

+65
-12
lines changed

implementation/src/main/java/io/smallrye/config/SecuritySupport.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,26 @@
2424
/**
2525
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2018 Red Hat inc.
2626
*/
27-
public class SecuritySupport {
27+
class SecuritySupport {
2828
private static final Logger LOG = Logger.getLogger("io.smallrye.config");
2929

3030
private SecuritySupport() {
3131
}
3232

33-
public static ClassLoader getContextClassLoader() {
34-
return AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> {
35-
ClassLoader tccl = null;
36-
try {
37-
tccl = Thread.currentThread().getContextClassLoader();
38-
} catch (SecurityException ex) {
39-
LOG.warn("Unable to get context classloader instance.", ex);
40-
}
41-
return tccl;
42-
});
33+
static ClassLoader getContextClassLoader() {
34+
if (System.getSecurityManager() == null) {
35+
return Thread.currentThread().getContextClassLoader();
36+
} else {
37+
return AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> {
38+
ClassLoader tccl = null;
39+
try {
40+
tccl = Thread.currentThread().getContextClassLoader();
41+
} catch (SecurityException ex) {
42+
LOG.warn("Unable to get context classloader instance.", ex);
43+
}
44+
return tccl;
45+
});
46+
}
4347
}
4448

4549
}

implementation/src/main/java/io/smallrye/config/inject/ConfigProducer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package io.smallrye.config.inject;
1818

19-
import static io.smallrye.config.SecuritySupport.getContextClassLoader;
19+
import static io.smallrye.config.inject.SecuritySupport.getContextClassLoader;
2020

2121
import java.io.Serializable;
2222
import java.util.*;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2018 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.smallrye.config.inject;
18+
19+
import java.security.AccessController;
20+
import java.security.PrivilegedAction;
21+
22+
import org.jboss.logging.Logger;
23+
24+
/**
25+
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2018 Red Hat inc.
26+
*/
27+
class SecuritySupport {
28+
private static final Logger LOG = Logger.getLogger("io.smallrye.config");
29+
30+
private SecuritySupport() {
31+
}
32+
33+
static ClassLoader getContextClassLoader() {
34+
if (System.getSecurityManager() == null) {
35+
return Thread.currentThread().getContextClassLoader();
36+
} else {
37+
return AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> {
38+
ClassLoader tccl = null;
39+
try {
40+
tccl = Thread.currentThread().getContextClassLoader();
41+
} catch (SecurityException ex) {
42+
LOG.warn("Unable to get context classloader instance.", ex);
43+
}
44+
return tccl;
45+
});
46+
}
47+
}
48+
49+
}

0 commit comments

Comments
 (0)