Skip to content

Commit bba14ab

Browse files
Added system/ping endpoint to the list of apis accesible outside localhost (#4399)
fixes #4397 Signed-off-by: Gino Augustine <ginoaugustine@gmail.com>
1 parent 884eeb2 commit bba14ab

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

apiary.apib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ HIFORMAT: 1A
44

55
OpenGrok RESTful API documentation. The following endpoints are accessible under `/api/v1` with the exception of `/metrics`.
66

7-
Besides `/suggester`, `/search` and `/metrics` endpoints, everything is accessible from `localhost` only
7+
Besides `/suggester`, `/search`, `/system/ping` and `/metrics` endpoints, everything is accessible from `localhost` only
88
unless authentication bearer tokens are configured in the web application and used via the 'Authorization' HTTP header
99
(within HTTPS connection).
1010

opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/SystemController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@
4747
import java.util.logging.Level;
4848
import java.util.logging.Logger;
4949

50-
@Path("/system")
50+
@Path(SystemController.PATH)
5151
public class SystemController {
5252

53+
public static final String PATH = "system";
54+
5355
private final RuntimeEnvironment env = RuntimeEnvironment.getInstance();
5456

5557
private static final Logger LOGGER = LoggerFactory.getLogger(SystemController.class);

opengrok-web/src/main/java/org/opengrok/web/api/v1/filter/IncomingFilter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.opengrok.web.api.v1.controller.HistoryController;
4040
import org.opengrok.web.api.v1.controller.SearchController;
4141
import org.opengrok.web.api.v1.controller.SuggesterController;
42+
import org.opengrok.web.api.v1.controller.SystemController;
4243

4344
import java.io.IOException;
4445
import java.net.InetAddress;
@@ -70,7 +71,8 @@ public class IncomingFilter implements ContainerRequestFilter, ConfigurationChan
7071
*/
7172
private static final Set<String> allowedPaths = new HashSet<>(Arrays.asList(
7273
SearchController.PATH, SuggesterController.PATH, SuggesterController.PATH + "/config",
73-
HistoryController.PATH, FileController.PATH, AnnotationController.PATH));
74+
HistoryController.PATH, FileController.PATH, AnnotationController.PATH,
75+
SystemController.PATH + "/ping"));
7476

7577
@Context
7678
private HttpServletRequest request;
@@ -136,7 +138,7 @@ public void filter(final ContainerRequestContext context) {
136138
}
137139

138140
if (allowedPaths.contains(path)) {
139-
LOGGER.log(Level.FINEST, "allowing request to {0} based on whitelisted path", path);
141+
LOGGER.log(Level.FINEST, "allowing request to {0} based on allow listed path", path);
140142
return;
141143
}
142144

opengrok-web/src/test/java/org/opengrok/web/api/v1/filter/IncomingFilterTest.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ private ContainerRequestContext mockContainerRequestContext(final String path) {
198198

199199
@Test
200200
public void localhostTest() throws Exception {
201-
assertFilterDoesNotBlockAddress("127.0.0.1");
201+
assertFilterDoesNotBlockAddress("127.0.0.1", "test");
202202
}
203203

204-
private void assertFilterDoesNotBlockAddress(final String remoteAddr) throws Exception {
204+
private void assertFilterDoesNotBlockAddress(final String remoteAddr, final String url) throws Exception {
205205
IncomingFilter filter = mockWithRemoteAddress(remoteAddr);
206206

207-
ContainerRequestContext context = mockContainerRequestContext("test");
207+
ContainerRequestContext context = mockContainerRequestContext(url);
208208

209209
ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
210210

@@ -215,19 +215,32 @@ private void assertFilterDoesNotBlockAddress(final String remoteAddr) throws Exc
215215

216216
@Test
217217
public void localhostIPv6Test() throws Exception {
218-
assertFilterDoesNotBlockAddress("0:0:0:0:0:0:0:1");
218+
assertFilterDoesNotBlockAddress("0:0:0:0:0:0:0:1", "test");
219219
}
220220

221221
@Test
222222
public void searchTest() throws Exception {
223-
IncomingFilter filter = mockWithRemoteAddress("10.0.0.1");
223+
assertFilterDoesNotBlockAddress("10.0.0.1", "search");
224+
}
224225

225-
ContainerRequestContext context = mockContainerRequestContext("search");
226+
@Test
227+
public void systemPingRemoteWithoutTokenTest() throws Exception {
228+
assertFilterDoesNotBlockAddress("10.0.0.1", "system/ping");
229+
}
230+
231+
@Test
232+
public void systemPathDescWithoutTokenTest() throws Exception {
233+
234+
IncomingFilter filter = mockWithRemoteAddress("192.168.1.1");
235+
236+
ContainerRequestContext context = mockContainerRequestContext("system/pathdesc");
226237

227238
ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
228239

229240
filter.filter(context);
230241

231-
verify(context, never()).abortWith(captor.capture());
242+
verify(context).abortWith(captor.capture());
243+
244+
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), captor.getValue().getStatus());
232245
}
233246
}

0 commit comments

Comments
 (0)