Skip to content

Commit fe56524

Browse files
authored
Fix Fortify security scanning (#1066)
* Fix Fortify security scanning * Arbitrary file access during archive extraction ("Zip Slip") Issue: 207277 * Remove GX Jar ClassLoader that has security issues and is not used.
1 parent aec51b0 commit fe56524

File tree

4 files changed

+17
-282
lines changed

4 files changed

+17
-282
lines changed

android/src/main/java/com/genexus/db/Namespace.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ public class Namespace extends AbstractNamespace
1616
public static final int GXDB_CLIENT = 0;
1717
public static final int GXDB_SERVER = 1;
1818
private static Hashtable namespaceList = new Hashtable();
19-
20-
private GXJarClassLoader classLoader;
21-
2219
private Hashtable dataSources = new Hashtable();
2320
private String name;
2421

@@ -233,27 +230,6 @@ public static Namespace getNamespace(String name)
233230

234231
public void reset()
235232
{
236-
if (classLoader != null)
237-
{
238-
classLoader = null;
239-
/* try
240-
{
241-
classLoader.resetClassLoader();
242-
}
243-
catch (java.io.IOException e)
244-
{
245-
System.err.println("Error resetting namespace classloader " + e.getMessage());
246-
}
247-
*/
248-
}
249-
}
250-
251-
public synchronized GXJarClassLoader getClassLoader()
252-
{
253-
if(classLoader == null)
254-
classLoader = new GXJarClassLoader(classesArchive, autoReload);
255-
else classLoader = classLoader.getClassLoaderInstance();
256-
return classLoader;
257233
}
258234

259235
public int getDataSourceCount()

common/src/main/java/com/genexus/GXJarClassLoader.java

Lines changed: 0 additions & 235 deletions
This file was deleted.

gxcompress/src/main/java/com/genexus/compression/GXCompressor.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,9 @@ private static void decompressZip(File archive, String directory) throws IOExcep
588588
ZipEntry zipEntry;
589589
while ((zipEntry = zis.getNextEntry()) != null) {
590590
File newFile = new File(directory, zipEntry.getName());
591+
if (HasZipSlipVulnerability(newFile, directory)) {
592+
throw new IOException("Bad tar entry: " + zipEntry.getName());
593+
}
591594
if (zipEntry.isDirectory()) {
592595
if (!newFile.isDirectory() && !newFile.mkdirs()) {
593596
throw new IOException("Failed to create directory " + newFile);
@@ -614,6 +617,9 @@ private static void decompress7z(File archive, String directory) throws IOExcept
614617
SevenZArchiveEntry entry;
615618
while ((entry = sevenZFile.getNextEntry()) != null) {
616619
File newFile = new File(directory, entry.getName());
620+
if (HasZipSlipVulnerability(newFile, directory)) {
621+
throw new IOException("Bad tar entry: " + entry.getName());
622+
}
617623
if (entry.isDirectory()) {
618624
if (!newFile.isDirectory() && !newFile.mkdirs()) {
619625
throw new IOException("Failed to create directory " + newFile);
@@ -640,6 +646,9 @@ private static void decompressTar(File archive, String directory) throws IOExcep
640646
TarArchiveEntry entry;
641647
while ((entry = tis.getNextEntry()) != null) {
642648
File newFile = new File(directory, entry.getName());
649+
if (HasZipSlipVulnerability(newFile, directory)) {
650+
throw new IOException("Bad tar entry: " + entry.getName());
651+
}
643652
if (entry.isDirectory()) {
644653
if (!newFile.isDirectory() && !newFile.mkdirs()) {
645654
throw new IOException("Failed to create directory " + newFile);
@@ -787,4 +796,12 @@ private static void decompressJar(File archive, String directory) throws IOExcep
787796
}
788797
}
789798
}
799+
800+
// Check for Zip Slip vulnerability: ensure extracted file remains within target directory
801+
// Use Path.normalize() and Path.startsWith()
802+
private static boolean HasZipSlipVulnerability(File file, String directory) {
803+
java.nio.file.Path destDirPath = new File(directory).toPath().toAbsolutePath().normalize();
804+
java.nio.file.Path newFilePath = file.toPath().toAbsolutePath().normalize();
805+
return !newFilePath.startsWith(destDirPath);
806+
}
790807
}

java/src/main/java/com/genexus/db/Namespace.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public class Namespace extends AbstractNamespace
1818
public static final int GXDB_SERVER = 1;
1919
private static ConcurrentHashMap<String, String> namespaceListCheck = new ConcurrentHashMap<String, String>();
2020
private static ConcurrentHashMap<String, Namespace> namespaceList = new ConcurrentHashMap<String, Namespace>();
21-
22-
private GXJarClassLoader classLoader;
2321
private ConcurrentHashMap<String, DataSource> dataSources = new ConcurrentHashMap<String, DataSource>();
2422

2523
private String name;
@@ -257,19 +255,6 @@ public static Namespace getNamespace(String name)
257255

258256
public void reset()
259257
{
260-
if (classLoader != null)
261-
{
262-
classLoader = null;
263-
/* try
264-
{
265-
classLoader.resetClassLoader();
266-
}
267-
catch (java.io.IOException e)
268-
{
269-
System.err.println("Error resetting namespace classloader " + e.getMessage());
270-
}
271-
*/
272-
}
273258
for (Enumeration<UserInformation> en = DBConnectionManager.getInstance().getServerConnections(); en.hasMoreElements();)
274259
{
275260
ServerUserInformation user = (ServerUserInformation) en.nextElement();
@@ -280,14 +265,6 @@ public void reset()
280265
}
281266
}
282267

283-
public synchronized GXJarClassLoader getClassLoader()
284-
{
285-
if(classLoader == null)
286-
classLoader = new GXJarClassLoader(classesArchive, autoReload);
287-
else classLoader = classLoader.getClassLoaderInstance();
288-
return classLoader;
289-
}
290-
291268
public int getDataSourceCount()
292269
{
293270
return dataSources.size();

0 commit comments

Comments
 (0)