Skip to content

Commit 54aac5b

Browse files
author
Vladimir Kotal
committed
strip repository user-info from repository list view
fixes #2004
1 parent 91712be commit 54aac5b

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,8 +1675,31 @@ public static boolean isHttpUri(String string) {
16751675
return url.getProtocol().equals("http") || url.getProtocol().equals("https");
16761676
}
16771677

1678+
protected final static String REDACTED_USER_INFO = "redacted_by_OpenGrok";
1679+
1680+
/**
1681+
* If given path is a URL, return the string representation with the user-info part filtered out.
1682+
* @param path path to object
1683+
* @return either the original string or string representation of URL with the user-info part removed
1684+
*/
1685+
public static String redactUrl(String path) {
1686+
URL url;
1687+
try {
1688+
url = new URL(path);
1689+
} catch (MalformedURLException e) {
1690+
// not an URL
1691+
return path;
1692+
}
1693+
if (url.getUserInfo() != null) {
1694+
return url.toString().replace(url.getUserInfo(),
1695+
REDACTED_USER_INFO);
1696+
} else {
1697+
return url.toString();
1698+
}
1699+
}
1700+
16781701
/**
1679-
* Build a html link to the given http url. If the URL is not an http URL
1702+
* Build a HTML link to the given HTTP URL. If the URL is not an http URL
16801703
* then it is returned as it was received. This has the same effect as
16811704
* invoking <code>linkify(url, true)</code>.
16821705
*

opengrok-indexer/src/test/java/org/opengrok/indexer/web/UtilTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,16 @@ public void testIsUrl() {
350350
assertFalse(Util.isHttpUri("smtp://example.com/OpenGrok/OpenGrok"));
351351
}
352352

353+
@Test
354+
public void testRedactUrl() {
355+
assertEquals("/foo/bar", Util.redactUrl("/foo/bar"));
356+
assertEquals("http://foo/bar?r=xxx", Util.redactUrl("http://foo/bar?r=xxx"));
357+
assertEquals("http://" + Util.REDACTED_USER_INFO + "@foo/bar?r=xxx",
358+
Util.redactUrl("http://user@foo/bar?r=xxx"));
359+
assertEquals("http://" + Util.REDACTED_USER_INFO + "@foo/bar?r=xxx",
360+
Util.redactUrl("http://user:pass@foo/bar?r=xxx"));
361+
}
362+
353363
@Test
354364
public void testLinkify() throws URISyntaxException, MalformedURLException {
355365
assertTrue(Util.linkify("http://www.example.com")

opengrok-web/src/main/webapp/repos.jspf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
171171
<span class="important-note important-note-rounded" data-messages='<%= messages %>'>!</span>
172172
<% } %>
173173
</td><%
174-
String parent = ri.getParent();
174+
String parent = Util.redactUrl(ri.getParent());
175175
if (parent == null) {
176176
parent = "N/A";
177177
}
@@ -301,7 +301,7 @@ Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
301301
<span class="important-note important-note-rounded" data-messages='<%= messages %>'>!</span>
302302
<% } %>
303303
</td><%
304-
String parent = ri.getParent();
304+
String parent = Util.redactUrl(ri.getParent());
305305
if (parent == null) {
306306
parent = "N/A";
307307
}

0 commit comments

Comments
 (0)