Skip to content

Commit 53d11a0

Browse files
author
Vladimir Kotal
committed
check whether URL is valid
fixes #2216
1 parent a473ead commit 53d11a0

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

opengrok-indexer/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
153153
<artifactId>org.suigeneris.jrcs.rcs</artifactId>
154154
<version>0.4.2</version>
155155
</dependency>
156+
<dependency>
157+
<groupId>commons-validator</groupId>
158+
<artifactId>commons-validator</artifactId>
159+
<version>1.4.0</version>
160+
</dependency>
156161
</dependencies>
157162

158163
<build>

opengrok-indexer/src/main/java/org/opengrok/indexer/index/Indexer.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
import java.util.logging.Level;
4646
import java.util.logging.Logger;
4747
import java.util.stream.Collectors;
48+
49+
import org.apache.commons.validator.routines.UrlValidator;
4850
import org.opengrok.indexer.Info;
4951
import org.opengrok.indexer.analysis.AnalyzerGuru;
5052
import org.opengrok.indexer.analysis.AnalyzerGuruHelp;
@@ -729,9 +731,14 @@ public static String[] parseOptions(String[] argv) throws ParseException {
729731

730732
parser.on("-U", "--host", "=protocol://host:port/contextPath",
731733
"Send the current configuration to the specified address").Do(webAddr -> {
732-
env = RuntimeEnvironment.getInstance();
733-
734734
host = (String) webAddr;
735+
String[] schemes = {"http", "https"};
736+
UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS);
737+
if (!urlValidator.isValid(host)) {
738+
die("URL '" + host + "' is not valid.");
739+
}
740+
741+
env = RuntimeEnvironment.getInstance();
735742
env.setConfigHost(host);
736743
}
737744
);
@@ -790,6 +797,12 @@ public static String[] parseOptions(String[] argv) throws ParseException {
790797
}
791798

792799
private static void checkConfiguration() {
800+
env = RuntimeEnvironment.getInstance();
801+
802+
if (noindex && (env.getConfigHost() == null || env.getConfigHost().isEmpty())) {
803+
die("Missing host URL");
804+
}
805+
793806
if (repositories.size() > 0 && !cfg.isHistoryEnabled()) {
794807
die("Repositories were specified however history is off");
795808
}

0 commit comments

Comments
 (0)