Skip to content
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

5.0 fix security review issues #2983

Merged
merged 6 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ plugins {
id 'maven-publish'
id 'antlr'
id "org.sonarqube"
id "com.diffplug.spotless" version "6.7.2"
}

spotless {
java {
target 'src/*/java/**/*.java'
removeUnusedImports()
}
}

archivesBaseName = "apoc"
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/apoc/Pools.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public void shutdown() throws Exception {
try {
service.shutdown();
service.awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException ignore) {

} catch (InterruptedException e) {
throw new RuntimeException("Shutdown failed to complete with error: " + e.getMessage());
}
});
}
Expand Down
4 changes: 0 additions & 4 deletions core/src/main/java/apoc/TTLConfigExtensionFactory.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package apoc;

import org.neo4j.annotations.service.ServiceProvider;
import org.neo4j.configuration.Config;
import org.neo4j.dbms.api.DatabaseManagementService;
import org.neo4j.kernel.api.procedure.GlobalProcedures;
import org.neo4j.kernel.extension.ExtensionFactory;
import org.neo4j.kernel.extension.ExtensionType;
import org.neo4j.kernel.extension.context.ExtensionContext;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.kernel.lifecycle.Lifecycle;
import org.neo4j.logging.internal.LogService;

/**
* a kernel extension for the TTL config
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/agg/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.neo4j.graphdb.Relationship;
import org.neo4j.procedure.*;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/agg/Median.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
Expand Down
4 changes: 0 additions & 4 deletions core/src/main/java/apoc/agg/Product.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package apoc.agg;

import org.HdrHistogram.Histogram;
import org.neo4j.procedure.*;

import java.util.ArrayList;
import java.util.List;

/**
* @author mh
* @since 18.12.17
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/apoc/convert/Convert.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,11 @@ private Long parseLongString(String input) {
} catch (NumberFormatException nfe) {
try {
return (long)Double.parseDouble(input);
} catch(NumberFormatException nfe2) {}
} catch(NumberFormatException nfe2) {
// String was not able to be parsed, return null
ncordon marked this conversation as resolved.
Show resolved Hide resolved
return null;
}
}
return null;
}

@UserFunction
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/apoc/date/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import apoc.util.DateFormatUtil;
import apoc.util.Util;
import org.apache.commons.lang3.StringUtils;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.procedure.*;

import java.text.DateFormat;
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/export/csv/CsvHeaderField.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package apoc.export.csv;

import apoc.meta.Meta;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import apoc.export.util.ExportConfig;
import com.fasterxml.jackson.core.JsonGenerator;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/apoc/export/util/CountingInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.*;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;

/**
* @author mh
Expand All @@ -16,8 +17,8 @@ public class CountingInputStream extends FilterInputStream implements SizeCounte
private long count=0;
private long newLines;

public CountingInputStream(File file) throws FileNotFoundException {
super(toBufferedStream(new FileInputStream(file)));
public CountingInputStream(File file) throws IOException {
super(toBufferedStream(Files.newInputStream(file.toPath())));
this.total = file.length();
}
public CountingInputStream(InputStream stream, long total) throws FileNotFoundException {
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/export/util/ExportConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package apoc.export.util;

import apoc.export.cypher.formatter.CypherFormat;
import apoc.util.CompressionAlgo;
import apoc.util.CompressionConfig;
import apoc.util.Util;

Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/export/util/MetaInformation.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.ResultTransformer;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/java/apoc/get/Get.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import apoc.result.RelationshipResult;
import apoc.util.Util;
import org.neo4j.graphdb.Transaction;
import org.neo4j.procedure.Context;
import org.neo4j.procedure.Description;
import org.neo4j.procedure.Name;
import org.neo4j.procedure.Procedure;

import java.util.stream.Stream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.lang.reflect.Array;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.List;
import java.util.Map;

import static org.apache.commons.text.WordUtils.capitalize;
import static org.apache.commons.text.WordUtils.capitalizeFully;

public class LabelBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/apoc/hashing/Fingerprinting.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Formatter;
Expand All @@ -25,7 +24,6 @@
import java.util.TreeMap;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class Fingerprinting {
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/apoc/help/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public Help() {
}
} catch (IOException e) {
// Failed to load extended file
throw new RuntimeException("Failed to load extended file with error: " + e.getMessage());
}
}

Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/index/SchemaIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.neo4j.internal.kernel.api.*;
import org.neo4j.internal.schema.IndexDescriptor;
import org.neo4j.internal.schema.SchemaDescriptors;
import org.neo4j.io.pagecache.context.CursorContext;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.impl.api.KernelStatement;
import org.neo4j.kernel.impl.coreapi.InternalTransaction;
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/load/Xml.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/meta/Meta.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package apoc.meta.tablesforlabels;

import apoc.meta.Tables4LabelsProfile;
import org.neo4j.graphdb.Label;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package apoc.meta.tablesforlabels;

import apoc.meta.Meta.ConstraintTracker;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Entity;
import org.neo4j.graphdb.schema.ConstraintDefinition;

import java.util.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
* A profile of a particular ordered label set (or relationship type) has a set of possible properties that can exist, and
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package apoc.meta.tablesforlabels;
import org.neo4j.graphdb.Label;

import java.util.*;

Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/periodic/PeriodicUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.ToLongFunction;
import java.util.regex.Pattern;
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/refactor/GraphRefactoring.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
Expand Down
9 changes: 6 additions & 3 deletions core/src/main/java/apoc/refactor/util/PropertiesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ public static void combineProperties(Map.Entry<String, Object> prop, Entity targ
else
values.add(prop.getValue());
Object array = createPropertyValueFromSet(values, refactorConfig);
target.setProperty(prop.getKey(), array);
if (array != null) {
target.setProperty(prop.getKey(), array);
}
}
}

private static Object createPropertyValueFromSet(Set<Object> input, RefactorConfig refactorConfig) {
Object array = null;
Object array;
try {
if (input.size() == 1 && !refactorConfig.isSingleElementAsArray()) {
return input.toArray()[0];
Expand All @@ -79,7 +81,8 @@ private static Object createPropertyValueFromSet(Set<Object> input, RefactorConf
}
}
}
} catch (Exception e) {
} catch (NegativeArraySizeException | ClassNotFoundException e) {
return null;
}
return array;
}
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/result/AssertSchemaResult.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package apoc.result;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/apoc/result/Empty.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package apoc.result;

import apoc.meta.Meta;

import java.util.stream.Stream;

/**
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/result/GraphResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;

import java.util.Collection;
import java.util.List;

/**
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/apoc/result/LongResult.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package apoc.result;

import java.util.stream.Stream;

/**
* @author mh
* @since 26.02.16
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/schema/Schemas.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package apoc.schema;

import apoc.Pools;
import apoc.result.AssertSchemaResult;
import apoc.result.IndexConstraintNodeInfo;
import apoc.result.IndexConstraintRelationshipInfo;
Expand Down
5 changes: 0 additions & 5 deletions core/src/main/java/apoc/text/Phonetic.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

import org.apache.commons.codec.language.DoubleMetaphone;
import org.neo4j.procedure.Description;
import apoc.result.LongResult;
import apoc.result.StringResult;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.language.Soundex;
import org.neo4j.procedure.Name;
import org.neo4j.procedure.Procedure;
import org.neo4j.procedure.UserFunction;

import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/util/CompressionAlgo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset;

import static apoc.ApocConfig.apocConfig;
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/apoc/util/DateParseUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static TemporalAccessor dateParse(String value, Class<? extends TemporalA
return getParse(date, value);
}
} catch (Exception e) {
// Ignore here as we are in a loop checking formats
// if all formats fail, a later exception will be called
continue;
}
}
Expand All @@ -38,7 +40,7 @@ public static TemporalAccessor dateParse(String value, Class<? extends TemporalA
} catch (Exception e) {
throw new RuntimeException(e);
} catch (Throwable throwable) {
throwable.printStackTrace();
throw new RuntimeException(throwable.getMessage());
}
throw new RuntimeException("Can't format the date with the pattern");
}
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory;
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/apoc/util/MapUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package apoc.util;

import java.util.LinkedHashMap;
import java.util.Map;

/**
Expand Down
Loading