Skip to content

Commit c480822

Browse files
authored
fix: prevent rogue base suppression files (#7544)
2 parents 1a3b4fa + 3710914 commit c480822

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

core/src/main/java/org/owasp/dependencycheck/analyzer/AbstractSuppressionAnalyzer.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.nio.file.Path;
2727
import java.nio.file.StandardCopyOption;
2828
import java.util.ArrayList;
29+
import java.util.Iterator;
2930
import java.util.List;
3031
import java.util.Set;
3132
import java.util.regex.Pattern;
@@ -188,23 +189,33 @@ private void loadSuppressionBaseData(final Engine engine) throws SuppressionPars
188189
}
189190

190191
/**
191-
* Loads all the base suppression rules packaged with the application.
192+
* Loads the base suppression rules packaged with the application.
192193
*
193194
* @param parser The suppression parser to use
194195
* @param engine a reference the dependency-check engine
195196
* @throws SuppressionParseException thrown if the XML cannot be parsed.
196197
*/
197198
private void loadPackagedSuppressionBaseData(final SuppressionParser parser, final Engine engine) throws SuppressionParseException {
198-
final List<SuppressionRule> ruleList;
199-
try (InputStream in = FileUtils.getResourceAsStream(BASE_SUPPRESSION_FILE)) {
200-
if (in == null) {
201-
throw new SuppressionParseException("Suppression rules `" + BASE_SUPPRESSION_FILE + "` could not be found");
202-
}
199+
List<SuppressionRule> ruleList = null;
200+
URL jarLocation = AbstractSuppressionAnalyzer.class.getProtectionDomain().getCodeSource().getLocation();
201+
String suppressionFileLocation = jarLocation.getFile();
202+
if (suppressionFileLocation.endsWith(".jar")) {
203+
suppressionFileLocation = "jar:file:" + suppressionFileLocation + "!/" + BASE_SUPPRESSION_FILE;
204+
} else {
205+
suppressionFileLocation = "file:" + suppressionFileLocation + BASE_SUPPRESSION_FILE;
206+
}
207+
URL baseSuppresssionURL = null;
208+
try {
209+
baseSuppresssionURL = new URL(suppressionFileLocation);
210+
} catch (MalformedURLException e) {
211+
throw new SuppressionParseException("Unable to load the base suppression data file", e);
212+
}
213+
try (InputStream in = baseSuppresssionURL.openStream()) {
203214
ruleList = parser.parseSuppressionRules(in);
204215
} catch (SAXException | IOException ex) {
205216
throw new SuppressionParseException("Unable to parse the base suppression data file", ex);
206217
}
207-
if (!ruleList.isEmpty()) {
218+
if (ruleList != null && !ruleList.isEmpty()) {
208219
if (engine.hasObject(SUPPRESSION_OBJECT_KEY)) {
209220
@SuppressWarnings("unchecked")
210221
final List<SuppressionRule> rules = (List<SuppressionRule>) engine.getObject(SUPPRESSION_OBJECT_KEY);

0 commit comments

Comments
 (0)