|
| 1 | + |
1 | 2 | package io.shiftleft.controller; |
2 | 3 |
|
3 | 4 | import io.shiftleft.model.Account; |
@@ -216,55 +217,52 @@ public void loadSettings(HttpServletResponse httpResponse, WebRequest request) t |
216 | 217 | * @param request |
217 | 218 | * @throws Exception |
218 | 219 | */ |
219 | | -@RequestMapping(value = "/saveSettings", method = RequestMethod.GET) |
220 | | -public void saveSettings(HttpServletResponse httpResponse, WebRequest request) throws Exception { |
| 220 | + @RequestMapping(value = "/saveSettings", method = RequestMethod.GET) |
| 221 | + public void saveSettings(HttpServletResponse httpResponse, WebRequest request) throws Exception { |
221 | 222 | // "Settings" will be stored in a cookie |
222 | 223 | // schema: base64(filename,value1,value2...), md5sum(base64(filename,value1,value2...)) |
223 | 224 |
|
224 | 225 | if (!checkCookie(request)){ |
225 | | - httpResponse.getOutputStream().println("Error"); |
226 | | - throw new Exception("cookie is incorrect"); |
| 226 | + httpResponse.getOutputStream().println("Error"); |
| 227 | + throw new Exception("cookie is incorrect"); |
227 | 228 | } |
228 | 229 |
|
229 | 230 | String settingsCookie = request.getHeader("Cookie"); |
230 | 231 | String[] cookie = settingsCookie.split(","); |
231 | | - if(cookie.length<2) { |
232 | | - httpResponse.getOutputStream().println("Malformed cookie"); |
233 | | - throw new Exception("cookie is incorrect"); |
| 232 | + if(cookie.length<2) { |
| 233 | + httpResponse.getOutputStream().println("Malformed cookie"); |
| 234 | + throw new Exception("cookie is incorrect"); |
234 | 235 | } |
235 | 236 |
|
236 | 237 | String base64txt = cookie[0].replace("settings=",""); |
237 | 238 |
|
238 | 239 | // Check md5sum |
239 | 240 | String cookieMD5sum = cookie[1]; |
240 | 241 | String calcMD5Sum = DigestUtils.md5Hex(base64txt); |
241 | | - if(!cookieMD5sum.equals(calcMD5Sum)) |
| 242 | + if(!cookieMD5sum.equals(calcMD5Sum)) |
242 | 243 | { |
243 | | - httpResponse.getOutputStream().println("Wrong md5"); |
244 | | - throw new Exception("Invalid MD5"); |
| 244 | + httpResponse.getOutputStream().println("Wrong md5"); |
| 245 | + throw new Exception("Invalid MD5"); |
245 | 246 | } |
246 | 247 |
|
247 | 248 | // Now we can store on filesystem |
248 | 249 | String[] settings = new String(Base64.getDecoder().decode(base64txt)).split(","); |
249 | | - // storage will have ClassPathResource as basepath |
| 250 | + // storage will have ClassPathResource as basepath |
250 | 251 | ClassPathResource cpr = new ClassPathResource("./static/"); |
251 | | - // Sanitize filename to prevent directory traversal |
252 | | - String filename = FilenameUtils.getName(settings[0]); |
253 | | - File file = new File(cpr.getPath() + filename); |
| 252 | + File file = new File(cpr.getPath()+settings[0]); |
254 | 253 | if(!file.exists()) { |
255 | | - file.getParentFile().mkdirs(); |
| 254 | + file.getParentFile().mkdirs(); |
256 | 255 | } |
257 | 256 |
|
258 | 257 | FileOutputStream fos = new FileOutputStream(file, true); |
259 | 258 | // First entry is the filename -> remove it |
260 | 259 | String[] settingsArr = Arrays.copyOfRange(settings, 1, settings.length); |
261 | | - // on setting at a line |
| 260 | + // on setting at a linez |
262 | 261 | fos.write(String.join("\n",settingsArr).getBytes()); |
263 | 262 | fos.write(("\n"+cookie[cookie.length-1]).getBytes()); |
264 | 263 | fos.close(); |
265 | 264 | httpResponse.getOutputStream().println("Settings Saved"); |
266 | | -} |
267 | | - |
| 265 | + } |
268 | 266 |
|
269 | 267 | /** |
270 | 268 | * Debug test for saving and reading a customer |
@@ -391,4 +389,3 @@ public void removeCustomer(@PathVariable("customerId") Long customerId, HttpServ |
391 | 389 | } |
392 | 390 |
|
393 | 391 | } |
394 | | - |
0 commit comments