Skip to content

Commit 9554a08

Browse files
Vladimir Kotalahornace
Vladimir Kotal
authored andcommitted
check for forbidden access explicitly
also revamp the forbidden page fixes #3658
1 parent 76f24e6 commit 9554a08

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

opengrok-web/src/main/java/org/opengrok/web/PageConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,11 @@ public String getPath() {
11041104
return path;
11051105
}
11061106

1107+
public boolean isUnreadable() {
1108+
File f = new File(getSourceRootPath(), getPath());
1109+
return f.exists() && !f.canRead();
1110+
}
1111+
11071112
/**
11081113
* Get the on disk file for the given path.
11091114
*

opengrok-web/src/main/webapp/WEB-INF/web.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@
268268
<error-code>404</error-code>
269269
<location>/enoent</location>
270270
</error-page>
271+
<error-page>
272+
<error-code>403</error-code>
273+
<location>/eforbidden</location>
274+
</error-page>
271275
<error-page>
272276
<error-code>500</error-code>
273277
<location>/error</location>

opengrok-web/src/main/webapp/eforbidden.jsp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,37 @@ information: Portions Copyright [yyyy] [name of copyright owner]
1616
1717
CDDL HEADER END
1818
19-
Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
19+
Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2020
Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
2121
--%>
22-
<%@page session="false" import="org.opengrok.web.PageConfig" %>
22+
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
23+
<%@page session="false" import="org.opengrok.web.PageConfig" %>
24+
<%@ page import="jakarta.servlet.http.HttpServletResponse" %>
2325
<%
24-
/* ---------------------- eforbidden.jspf start --------------------- */
26+
/* ---------------------- eforbidden.jsp start --------------------- */
2527
{
2628
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
27-
%>
29+
%><%@
30+
31+
include file="httpheader.jspf"
32+
33+
%><body>
34+
<div id="page">
35+
<div id="whole_header">
36+
<div id="header"><%@
37+
38+
include file="pageheader.jspf"
39+
40+
%></div>
41+
</div>
42+
<h3 class="error">Error: access forbidden</h3>
43+
<p>The request was forbidden. This can be either file/directory permissions problem or insufficient authorization.</p>
2844
<%= PageConfig.get(request).getEnv().getIncludeFiles().getForbiddenIncludeFileContent(false) %>
2945
<%
3046
}
31-
/* ---------------------- eforbidden.jspf end --------------------- */
47+
/* ---------------------- eforbidden.jsp end --------------------- */
48+
%><%@
49+
50+
include file="foot.jspf"
51+
3252
%>

opengrok-web/src/main/webapp/mast.jsp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ org.opengrok.web.PageConfig,
3434
org.opengrok.indexer.web.Prefix,
3535
org.opengrok.indexer.web.Util"%>
3636
<%@ page import="org.opengrok.indexer.web.messages.MessagesUtils" %>
37+
<%@ page import="jakarta.servlet.http.HttpServletResponse" %>
3738
<%
3839
/* ---------------------- mast.jsp start --------------------- */
3940
{
4041
PageConfig cfg = PageConfig.get(request);
42+
if (cfg.isUnreadable()) {
43+
response.sendError(HttpServletResponse.SC_FORBIDDEN);
44+
return;
45+
}
46+
4147
String redir = cfg.canProcess();
4248
if (redir == null || redir.length() > 0) {
4349
if (redir == null) {

0 commit comments

Comments
 (0)