Skip to content

Commit aa0db80

Browse files
committed
Improved: Check parameters passed in URLs (OFBIZ-13295)
Better completely bypass "Prevents stream exploitation" block in ControlFilter.java Also better uses the token bypassPreventsStreamExploitation in ControlFilterTests Conflicts handled by hand in ControlFilter.java
1 parent 63dc783 commit aa0db80

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,10 @@ public void doFilter(HttpServletRequest req, HttpServletResponse resp, FilterCha
174174
String context = req.getContextPath();
175175
HttpSession session = req.getSession();
176176

177-
// Prevents stream exploitation
178-
if (!isSolrTest()) {
179-
if (!isControlFilterTests()) {
180-
UrlServletHelper.setRequestAttributes(req, null, req.getServletContext());
181-
}
177+
if (!(isSolrTest() || isControlFilterTests())) {
178+
// Prevents stream exploitation
179+
UrlServletHelper.setRequestAttributes(req, null, req.getServletContext());
180+
UrlServletHelper.setRequestAttributes(req, null, req.getServletContext());
182181
Map<String, Object> parameters = UtilHttp.getParameterMap(req);
183182
boolean reject = false;
184183
if (!parameters.isEmpty()) {
@@ -197,10 +196,10 @@ public void doFilter(HttpServletRequest req, HttpServletResponse resp, FilterCha
197196
reject = true;
198197
}
199198
}
200-
if (reject) {
201-
Debug.logError("For security reason this URL is not accepted", MODULE);
202-
throw new RuntimeException("For security reason this URL is not accepted");
203-
}
199+
}
200+
if (reject) {
201+
Debug.logError("For security reason this URL is not accepted", MODULE);
202+
throw new RuntimeException("For security reason this URL is not accepted");
204203
}
205204
}
206205
}

framework/webapp/src/test/java/org/apache/ofbiz/webapp/control/ControlFilterTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void setUp() {
5858

5959
@Test
6060
public void filterWithExactAllowedPath() throws Exception {
61-
System.setProperty("ControlFilterTests", "runsAfterControlFilter");
61+
System.setProperty("ControlFilterTests", "bypassPreventsStreamExploitation");
6262
when(config.getInitParameter("redirectPath")).thenReturn("/foo");
6363
when(config.getInitParameter("allowedPaths")).thenReturn("/foo:/bar");
6464
when(req.getRequestURI()).thenReturn("/servlet/bar");
@@ -72,7 +72,7 @@ public void filterWithExactAllowedPath() throws Exception {
7272

7373
@Test
7474
public void filterWithAllowedSubPath() throws Exception {
75-
System.setProperty("ControlFilterTests", "runsAfterControlFilter");
75+
System.setProperty("ControlFilterTests", "bypassPreventsStreamExploitation");
7676
when(config.getInitParameter("redirectPath")).thenReturn("/foo");
7777
when(config.getInitParameter("allowedPaths")).thenReturn("/foo:/bar");
7878
when(req.getRequestURI()).thenReturn("/servlet/bar/baz");
@@ -86,7 +86,7 @@ public void filterWithAllowedSubPath() throws Exception {
8686

8787
@Test
8888
public void filterWithRedirection() throws Exception {
89-
System.setProperty("ControlFilterTests", "runsAfterControlFilter");
89+
System.setProperty("ControlFilterTests", "bypassPreventsStreamExploitation");
9090
when(config.getInitParameter("redirectPath")).thenReturn("/foo");
9191
when(config.getInitParameter("allowedPaths")).thenReturn("/bar:/baz");
9292
when(req.getRequestURI()).thenReturn("/missing/path");
@@ -99,7 +99,7 @@ public void filterWithRedirection() throws Exception {
9999

100100
@Test
101101
public void filterWithURIredirection() throws Exception {
102-
System.setProperty("ControlFilterTests", "runsAfterControlFilter");
102+
System.setProperty("ControlFilterTests", "bypassPreventsStreamExploitation");
103103
when(config.getInitParameter("redirectPath")).thenReturn("http://example.org/foo");
104104
when(config.getInitParameter("allowedPaths")).thenReturn("/foo:/bar");
105105
when(req.getRequestURI()).thenReturn("/baz");
@@ -112,7 +112,7 @@ public void filterWithURIredirection() throws Exception {
112112

113113
@Test
114114
public void bailsOutWithVariousErrorCodes() throws Exception {
115-
System.setProperty("ControlFilterTests", "runsAfterControlFilter");
115+
System.setProperty("ControlFilterTests", "bypassPreventsStreamExploitation");
116116
when(config.getInitParameter("allowedPaths")).thenReturn("/foo");
117117
when(req.getRequestURI()).thenReturn("/baz");
118118

@@ -143,7 +143,7 @@ public void bailsOutWithVariousErrorCodes() throws Exception {
143143

144144
@Test
145145
public void redirectAllAllowed() throws Exception {
146-
System.setProperty("ControlFilterTests", "runsAfterControlFilter");
146+
System.setProperty("ControlFilterTests", "bypassPreventsStreamExploitation");
147147
when(config.getInitParameter("redirectPath")).thenReturn("/bar");
148148
when(config.getInitParameter("forceRedirectAll")).thenReturn("Y");
149149
when(config.getInitParameter("allowedPaths")).thenReturn("/foo");
@@ -157,7 +157,7 @@ public void redirectAllAllowed() throws Exception {
157157

158158
@Test
159159
public void redirectAllNotAllowed() throws Exception {
160-
System.setProperty("ControlFilterTests", "runsAfterControlFilter");
160+
System.setProperty("ControlFilterTests", "bypassPreventsStreamExploitation");
161161
when(config.getInitParameter("redirectPath")).thenReturn("/bar");
162162
when(config.getInitParameter("forceRedirectAll")).thenReturn("Y");
163163
when(config.getInitParameter("allowedPaths")).thenReturn("/foo");
@@ -171,7 +171,7 @@ public void redirectAllNotAllowed() throws Exception {
171171

172172
@Test
173173
public void redirectAllRecursive() throws Exception {
174-
System.setProperty("ControlFilterTests", "runsAfterControlFilter");
174+
System.setProperty("ControlFilterTests", "bypassPreventsStreamExploitation");
175175
when(config.getInitParameter("redirectPath")).thenReturn("/foo");
176176
when(config.getInitParameter("forceRedirectAll")).thenReturn("Y");
177177
when(config.getInitParameter("allowedPaths")).thenReturn("/foo");

0 commit comments

Comments
 (0)