Skip to content

Commit da56919

Browse files
simonreschkyakdan
authored andcommitted
chore: exclude potentially dangerous tests by default
All tests that can perform potentially harmful side effects are tagged and excluded by default. The CI still tests all. Closes #971
1 parent 707c948 commit da56919

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

.bazelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,9 @@ common:quiet --noshow_progress
126126
test:fail-fast --notest_keep_going
127127
# Instruct test runners to fail a test target on the first failing test.
128128
test:fail-fast --test_runner_fail_fast
129+
130+
# Safety: by default on local runs, exclude tests tagged as dangerous
131+
# (e.g., those that could execute OS commands, touch the filesystem aggressively, or require network).
132+
test --test_tag_filters=-dangerous
133+
# In CI, include all tests.
134+
test:ci --test_tag_filters=

CONTRIBUTING.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ $ bazel test //...
7878
If you are bisecting a bug or otherwise want test execution to stop right after the first failure, use `--config=fail-fast`.
7979
This is especially useful with long-running or parameterized tests.
8080

81+
#### Potentially harmful tests
82+
83+
Some tests deliberately exercise vulnerable code with fuzzer input to e.g. assert specific findings reported by Jazzer.
84+
Due to the pseudo-random nature of fuzzing this can cause potentially harmful side effects on the host system which is
85+
why such tests are tagged with `"dangerous"` and not executed by default when running tests locally. You can run _all_
86+
tests by adding the flag
87+
88+
```bash
89+
--test_tag_filters=
90+
```
91+
92+
but this should be done with care. At worst the tests will execute arbitrary commands or open network connections to
93+
random addresses. Depending on the host OS the bazel test sandboxing can be a good first line of defence to prevent
94+
destructive side effects.
95+
8196
#### Debugging
8297

8398
##### Internal debugging

examples/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,10 @@ java_fuzz_target_test(
343343
"com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh",
344344
],
345345
fuzzer_args = ["-runs=100000"],
346-
tags = ["no-jdk8"],
346+
tags = [
347+
"dangerous",
348+
"no-jdk8",
349+
],
347350
target_class = "com.example.SpringCloudFunctionRoutingFuzzer",
348351
verify_crash_reproducer = False,
349352
deps = [

sanitizers/src/test/java/com/example/BUILD.bazel

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ java_fuzz_target_test(
1010
"com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh",
1111
"java.lang.ExceptionInInitializerError",
1212
],
13+
tags = ["dangerous"],
1314
target_class = "com.example.ObjectInputStreamDeserialization",
1415
)
1516

@@ -22,6 +23,7 @@ java_fuzz_target_test(
2223
"com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh",
2324
"java.lang.ExceptionInInitializerError",
2425
],
26+
tags = ["dangerous"],
2527
target_class = "com.example.ReflectiveCall",
2628
)
2729

@@ -33,6 +35,7 @@ java_fuzz_target_test(
3335
allowed_findings = [
3436
"com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh",
3537
],
38+
tags = ["dangerous"],
3639
target_class = "com.example.LibraryLoad",
3740
# loading of native libraries is very slow on macos,
3841
# especially using Java 17
@@ -49,6 +52,7 @@ java_fuzz_target_test(
4952
],
5053
allowed_findings = ["com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh"],
5154
expected_warning_or_error = "WARN: Some hooks could not be applied to class files built for Java 7 or lower.",
55+
tags = ["dangerous"],
5256
target_class = "com.example.ExpressionLanguageInjection",
5357
# The reproducer can't find jaz.Zer and thus doesn't crash.
5458
verify_crash_reproducer = False,
@@ -159,6 +163,7 @@ java_fuzz_target_test(
159163
"OsCommandInjectionProcessBuilder.java",
160164
],
161165
allowed_findings = ["com.code_intelligence.jazzer.api.FuzzerSecurityIssueCritical"],
166+
tags = ["dangerous"],
162167
target_class = "com.example.OsCommandInjectionProcessBuilder",
163168
verify_crash_reproducer = False,
164169
)
@@ -169,6 +174,7 @@ java_fuzz_target_test(
169174
"OsCommandInjectionRuntimeExec.java",
170175
],
171176
allowed_findings = ["com.code_intelligence.jazzer.api.FuzzerSecurityIssueCritical"],
177+
tags = ["dangerous"],
172178
target_class = "com.example.OsCommandInjectionRuntimeExec",
173179
verify_crash_reproducer = False,
174180
)
@@ -243,6 +249,7 @@ java_fuzz_target_test(
243249
# Reproducer does not find the honeypot library and doesn't have the hook.
244250
"java.lang.ExceptionInInitializerError",
245251
],
252+
tags = ["dangerous"],
246253
target_class = "com.example.ClassLoaderLoadClass",
247254
)
248255

@@ -489,6 +496,7 @@ java_fuzz_target_test(
489496
allowed_findings = [
490497
"com.code_intelligence.jazzer.api.FuzzerSecurityIssueMedium",
491498
],
499+
tags = ["dangerous"],
492500
target_class = "com.example.SsrfSocketConnect",
493501
verify_crash_reproducer = False,
494502
)
@@ -501,6 +509,7 @@ java_fuzz_target_test(
501509
allowed_findings = [
502510
"com.code_intelligence.jazzer.api.FuzzerSecurityIssueMedium",
503511
],
512+
tags = ["dangerous"],
504513
target_class = "com.example.SsrfSocketConnectToHost",
505514
verify_crash_reproducer = False,
506515
)
@@ -513,6 +522,7 @@ java_fuzz_target_test(
513522
allowed_findings = [
514523
"com.code_intelligence.jazzer.api.FuzzerSecurityIssueMedium",
515524
],
525+
tags = ["dangerous"],
516526
target_class = "com.example.SsrfUrlConnection",
517527
verify_crash_reproducer = False,
518528
)
@@ -525,7 +535,10 @@ java_fuzz_target_test(
525535
allowed_findings = [
526536
"com.code_intelligence.jazzer.api.FuzzerSecurityIssueMedium",
527537
],
528-
tags = ["no-jdk8"],
538+
tags = [
539+
"dangerous",
540+
"no-jdk8",
541+
],
529542
target_class = "com.example.SsrfHttpClient",
530543
verify_crash_reproducer = False,
531544
)

0 commit comments

Comments
 (0)