File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
src/java/detectors/cross_site_scripting Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ package detectors .cross_site_scripting ;
7
+
8
+ import org .springframework .web .bind .annotation .RequestParam ;
9
+ import org .springframework .web .servlet .ModelAndView ;
10
+
11
+ public class CrossSiteScripting {
12
+
13
+ // {fact rule=cross-site-scripting@v1.0 defects=1}
14
+ public ModelAndView inputSanitizationNonCompliant (@ RequestParam String favoriteColor ) {
15
+ ModelAndView modelAndView = new ModelAndView ();
16
+ modelAndView .setViewName ("jsp/example.jsp" );
17
+ // Noncompliant: user-supplied parameter might contain malicious content.
18
+ modelAndView .addObject ("preferredColor" , favoriteColor );
19
+ return modelAndView ;
20
+ }
21
+ // {/fact}
22
+
23
+ // {fact rule=cross-site-scripting@v1.0 defects=0}
24
+ public ModelAndView inputSanitizationCompliant (@ RequestParam String favoriteColor ) {
25
+ ModelAndView modelAndView = new ModelAndView ();
26
+ modelAndView .setViewName ("jsp/example.jsp" );
27
+ // Compliant: user-supplied parameter must be in allow-list.
28
+ if (favoriteColor .matches ("[a-z]+" )) {
29
+ modelAndView .addObject ("preferredColor" , favoriteColor );
30
+ } else {
31
+ throw new IllegalArgumentException ("Invalid color!" );
32
+ }
33
+ return modelAndView ;
34
+ }
35
+ // {/fact}
36
+
37
+ }
You can’t perform that action at this time.
0 commit comments