• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 Code Intelligence GmbH
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.example;
16 
17 import com.code_intelligence.jazzer.api.FuzzedDataProvider;
18 import com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh;
19 import com.code_intelligence.jazzer.api.FuzzerSecurityIssueMedium;
20 import com.google.json.JsonSanitizer;
21 
22 public class JsonSanitizerDenylistFuzzer {
fuzzerTestOneInput(FuzzedDataProvider data)23   public static void fuzzerTestOneInput(FuzzedDataProvider data) {
24     String input = data.consumeRemainingAsString();
25     String validJson;
26     try {
27       validJson = JsonSanitizer.sanitize(input, 10);
28     } catch (Exception e) {
29       return;
30     }
31 
32     // Check for forbidden substrings. As these would enable Cross-Site Scripting, treat every
33     // finding as a high severity vulnerability.
34     assert !validJson.contains("</script")
35         : new FuzzerSecurityIssueHigh("Output contains </script");
36     assert !validJson.contains("]]>") : new FuzzerSecurityIssueHigh("Output contains ]]>");
37 
38     // Check for more forbidden substrings. As these would not directly enable Cross-Site Scripting
39     // in general, but may impact script execution on the embedding page, treat each finding as a
40     // medium severity vulnerability.
41     assert !validJson.contains("<script")
42         : new FuzzerSecurityIssueMedium("Output contains <script");
43     assert !validJson.contains("<!--") : new FuzzerSecurityIssueMedium("Output contains <!--");
44   }
45 }
46