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

refactor: Java Security Ultimate Security Repo Scanner 2023 #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.Files;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
Expand Down Expand Up @@ -56,7 +57,7 @@ private File prepareSessionsXmlFile(ZipFile zipFile, ZipEntry entry) throws Exce

// Create the Channel for the destination
String fileName = entry.getName().replace('/', '_');
File file = File.createTempFile(fileName, null);
File file = Files.createTempFile(fileName, null).toFile();
FileOutputStream fos = new FileOutputStream(file);
FileChannel destinationChannel = fos.getChannel();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.eclipse.persistence.tools.workbench.utility;

import java.lang.reflect.Array;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -1635,7 +1636,7 @@ public static Object[] rotate(Object[] array, int distance) {
if (distance == 0) {
return array;
}
for (int cycleStart = 0, nMoved = 0; nMoved != len; cycleStart++) {
for (int cycleStart = 0, nMoved = 0; nMoved < len; cycleStart++) {
Object displaced = array[cycleStart];
int i = cycleStart;
do {
Expand Down Expand Up @@ -1676,7 +1677,7 @@ public static char[] rotate(char[] array, int distance) {
if (distance == 0) {
return array;
}
for (int cycleStart = 0, nMoved = 0; nMoved != len; cycleStart++) {
for (int cycleStart = 0, nMoved = 0; nMoved < len; cycleStart++) {
char displaced = array[cycleStart];
int i = cycleStart;
do {
Expand Down Expand Up @@ -1717,7 +1718,7 @@ public static int[] rotate(int[] array, int distance) {
if (distance == 0) {
return array;
}
for (int cycleStart = 0, nMoved = 0; nMoved != len; cycleStart++) {
for (int cycleStart = 0, nMoved = 0; nMoved < len; cycleStart++) {
int displaced = array[cycleStart];
int i = cycleStart;
do {
Expand Down Expand Up @@ -1758,7 +1759,7 @@ public static Set set(Object[] array) {
return set;
}

private static final Random RANDOM = new Random();
private static final Random RANDOM = new SecureRandom();

/**
* Return the array after "shuffling" it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.List;

import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
Expand Down Expand Up @@ -79,6 +80,26 @@ public final class XMLTools {
private static synchronized DocumentBuilderFactory documentBuilderFactory() {
if (documentBuilderFactory == null) {
documentBuilderFactory = DocumentBuilderFactory.newInstance();
String FEATURE = null;
try {
FEATURE = "http://xml.org/sax/features/external-parameter-entities";
documentBuilderFactory.setFeature(FEATURE, false);

FEATURE = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
documentBuilderFactory.setFeature(FEATURE, false);

FEATURE = "http://xml.org/sax/features/external-general-entities";
documentBuilderFactory.setFeature(FEATURE, false);

documentBuilderFactory.setXIncludeAware(false);
documentBuilderFactory.setExpandEntityReferences(false);

documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);

} catch (ParserConfigurationException e) {
throw new IllegalStateException("The feature '"
+ FEATURE + "' is not supported by your XML processor.", e);
}
}
return documentBuilderFactory;
}
Expand Down Expand Up @@ -452,6 +473,9 @@ public static void addSimpleTextNodes(Node parent, String childrenName, String c
private static synchronized TransformerFactory transformerFactory() {
if (transformerFactory == null) {
transformerFactory = TransformerFactory.newInstance();
transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
transformerFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
}
return transformerFactory;
}
Expand Down