1
1
/**
2
- * OWASP Benchmark v1.2
3
- *
4
- * This file is part of the Open Web Application Security Project (OWASP)
5
- * Benchmark Project. For details, please see
6
- * <a href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
- *
8
- * The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
- * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
- *
11
- * The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
12
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * @author Dave Wichers
16
- * @created 2015
17
- */
18
-
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
19
18
package org .owasp .benchmark .testcode ;
20
19
21
20
import java .io .IOException ;
22
-
23
21
import javax .servlet .ServletException ;
24
22
import javax .servlet .annotation .WebServlet ;
25
23
import javax .servlet .http .HttpServlet ;
26
24
import javax .servlet .http .HttpServletRequest ;
27
25
import javax .servlet .http .HttpServletResponse ;
28
26
29
- @ WebServlet (value = "/pathtraver-00/BenchmarkTest00001" )
27
+ @ WebServlet (value = "/pathtraver-00/BenchmarkTest00001" )
30
28
public class BenchmarkTest00001 extends HttpServlet {
31
-
32
- private static final long serialVersionUID = 1L ;
33
-
34
- @ Override
35
- public void doGet (HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException {
36
- response .setContentType ("text/html;charset=UTF-8" );
37
- javax .servlet .http .Cookie userCookie = new javax .servlet .http .Cookie ("BenchmarkTest00001" , "FileName" );
38
- userCookie .setMaxAge (60 *3 ); //Store cookie for 3 minutes
39
- userCookie .setSecure (true );
40
- userCookie .setPath (request .getRequestURI ());
41
- userCookie .setDomain (new java .net .URL (request .getRequestURL ().toString ()).getHost ());
42
- response .addCookie (userCookie );
43
- javax .servlet .RequestDispatcher rd = request .getRequestDispatcher ("/pathtraver-00/BenchmarkTest00001.html" );
44
- rd .include (request , response );
45
- }
46
29
47
- @ Override
48
- public void doPost (HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException {
49
- // some code
50
- response .setContentType ("text/html;charset=UTF-8" );
51
-
30
+ private static final long serialVersionUID = 1L ;
31
+
32
+ @ Override
33
+ public void doGet (HttpServletRequest request , HttpServletResponse response )
34
+ throws ServletException , IOException {
35
+ response .setContentType ("text/html;charset=UTF-8" );
36
+ javax .servlet .http .Cookie userCookie =
37
+ new javax .servlet .http .Cookie ("BenchmarkTest00001" , "FileName" );
38
+ userCookie .setMaxAge (60 * 3 ); // Store cookie for 3 minutes
39
+ userCookie .setSecure (true );
40
+ userCookie .setPath (request .getRequestURI ());
41
+ userCookie .setDomain (new java .net .URL (request .getRequestURL ().toString ()).getHost ());
42
+ response .addCookie (userCookie );
43
+ javax .servlet .RequestDispatcher rd =
44
+ request .getRequestDispatcher ("/pathtraver-00/BenchmarkTest00001.html" );
45
+ rd .include (request , response );
46
+ }
47
+
48
+ @ Override
49
+ public void doPost (HttpServletRequest request , HttpServletResponse response )
50
+ throws ServletException , IOException {
51
+ // some code
52
+ response .setContentType ("text/html;charset=UTF-8" );
52
53
53
- javax .servlet .http .Cookie [] theCookies = request .getCookies ();
54
-
55
- String param = "noCookieValueSupplied" ;
56
- if (theCookies != null ) {
57
- for (javax .servlet .http .Cookie theCookie : theCookies ) {
58
- if (theCookie .getName ().equals ("BenchmarkTest00001" )) {
59
- param = java .net .URLDecoder .decode (theCookie .getValue (), "UTF-8" );
60
- break ;
61
- }
62
- }
63
- }
54
+ javax .servlet .http .Cookie [] theCookies = request .getCookies ();
55
+
56
+ String param = "noCookieValueSupplied" ;
57
+ if (theCookies != null ) {
58
+ for (javax .servlet .http .Cookie theCookie : theCookies ) {
59
+ if (theCookie .getName ().equals ("BenchmarkTest00001" )) {
60
+ param = java .net .URLDecoder .decode (theCookie .getValue (), "UTF-8" );
61
+ break ;
62
+ }
63
+ }
64
+ }
64
65
65
-
66
66
String fileName = null ;
67
67
java .io .FileInputStream fis = null ;
68
68
69
69
try {
70
- fileName = org .owasp .benchmark .helpers .Utils .TESTFILES_DIR + param ;
71
- fis = new java .io .FileInputStream (new java .io .File (fileName ));
72
- byte [] b = new byte [1000 ];
73
- int size = fis .read (b );
74
- response .getWriter ().println (
75
- "The beginning of file: '" + org .owasp .esapi .ESAPI .encoder ().encodeForHTML (fileName )
76
- + "' is:\n \n " + org .owasp .esapi .ESAPI .encoder ().encodeForHTML (new String (b ,0 ,size ))
77
- );
70
+ fileName = org .owasp .benchmark .helpers .Utils .TESTFILES_DIR + param ;
71
+ fis = new java .io .FileInputStream (new java .io .File (fileName ));
72
+ byte [] b = new byte [1000 ];
73
+ int size = fis .read (b );
74
+ response .getWriter ()
75
+ .println (
76
+ "The beginning of file: '"
77
+ + org .owasp .esapi .ESAPI .encoder ().encodeForHTML (fileName )
78
+ + "' is:\n \n "
79
+ + org .owasp
80
+ .esapi
81
+ .ESAPI
82
+ .encoder ()
83
+ .encodeForHTML (new String (b , 0 , size )));
78
84
} catch (Exception e ) {
79
85
System .out .println ("Couldn't open FileInputStream on file: '" + fileName + "'" );
80
- response .getWriter ().println (
81
- "Problem getting FileInputStream: "
82
- + org .owasp .esapi .ESAPI .encoder ().encodeForHTML (e .getMessage ())
83
- );
86
+ response .getWriter ()
87
+ .println (
88
+ "Problem getting FileInputStream: "
89
+ + org .owasp
90
+ .esapi
91
+ .ESAPI
92
+ .encoder ()
93
+ .encodeForHTML (e .getMessage ()));
84
94
} finally {
85
95
if (fis != null ) {
86
96
try {
@@ -91,6 +101,5 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
91
101
}
92
102
}
93
103
}
94
- }
95
-
104
+ }
96
105
}
0 commit comments