|
25 | 25 | import java.util.ArrayList; |
26 | 26 | import java.util.Arrays; |
27 | 27 | import java.util.Collections; |
| 28 | +import java.util.LinkedList; |
28 | 29 | import java.util.List; |
| 30 | +import java.util.Map; |
29 | 31 | import java.util.Set; |
30 | 32 | import java.util.stream.Collectors; |
31 | 33 |
|
@@ -165,6 +167,35 @@ public void doFilter(HttpServletRequest req, HttpServletResponse resp, FilterCha |
165 | 167 | String context = req.getContextPath(); |
166 | 168 | HttpSession session = req.getSession(); |
167 | 169 |
|
| 170 | + // Prevents stream exploitation |
| 171 | + Map<String, Object> parameters = UtilHttp.getParameterMap(req); |
| 172 | + boolean reject = false; |
| 173 | + if (!parameters.isEmpty()) { |
| 174 | + for (String key : parameters.keySet()) { |
| 175 | + Object object = parameters.get(key); |
| 176 | + if (object.getClass().equals(String.class)) { |
| 177 | + String val = (String) object; |
| 178 | + if (val.contains("<")) { |
| 179 | + reject = true; |
| 180 | + } |
| 181 | + } else { |
| 182 | + @SuppressWarnings("unchecked") |
| 183 | + LinkedList<String> vals = (LinkedList<String>) parameters.get(key); |
| 184 | + for (String aVal : vals) { |
| 185 | + if (aVal.contains("<")) { |
| 186 | + reject = true; |
| 187 | + } |
| 188 | + } |
| 189 | + } |
| 190 | + } |
| 191 | + if (reject) { |
| 192 | + Debug.logError("For security reason this URL is not accepted", MODULE); |
| 193 | + throw new RuntimeException("For security reason this URL is not accepted"); |
| 194 | + } |
| 195 | + } |
| 196 | + |
| 197 | + |
| 198 | + |
168 | 199 | // Check if we are told to redirect everything. |
169 | 200 | if (redirectAll) { |
170 | 201 | // little trick here so we don't loop on ourselves |
|
0 commit comments