Skip to content

Commit 92fd464

Browse files
cushonError Prone Team
authored and
Error Prone Team
committed
Move BanSerializableRead annotations to an internal package
and fix some broken javadoc. PiperOrigin-RevId: 350871257
1 parent ea7b968 commit 92fd464

File tree

7 files changed

+18
-114
lines changed

7 files changed

+18
-114
lines changed

annotations/src/main/java/com/google/errorprone/annotations/SuppressBanSerializableCompletedSecurityReview.java

-35
This file was deleted.

annotations/src/main/java/com/google/errorprone/annotations/SuppressBanSerializableForLegacyCode.java

-35
This file was deleted.

core/src/main/java/com/google/errorprone/bugpatterns/BanSerializableRead.java

+3-26
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,17 @@
2828
import com.google.errorprone.BugPattern;
2929
import com.google.errorprone.BugPattern.SeverityLevel;
3030
import com.google.errorprone.VisitorState;
31-
import com.google.errorprone.annotations.SuppressBanSerializableCompletedSecurityReview;
32-
import com.google.errorprone.annotations.SuppressBanSerializableForLegacyCode;
3331
import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher;
34-
import com.google.errorprone.fixes.SuggestedFix;
35-
import com.google.errorprone.fixes.SuggestedFixes;
3632
import com.google.errorprone.matchers.Description;
3733
import com.google.errorprone.matchers.Matcher;
3834
import com.sun.source.tree.ExpressionTree;
3935
import com.sun.source.tree.MethodInvocationTree;
40-
import java.util.Optional;
4136

4237
/** A {@link BugChecker} that detects use of the unsafe {@link java.io.Serializable} API. */
4338
@BugPattern(
4439
name = "BanSerializableRead",
4540
summary = "Deserializing user input via the `Serializable` API is extremely dangerous",
46-
explanation =
47-
"The Java `Serializable` API is very powerful, and very dangerous. Any consumption of a"
48-
+ " serialized object that cannot be explicitly trusted will likely result in a"
49-
+ " critical remote code execution bug that will give an attacker control of the"
50-
+ " application."
51-
+ " Consider using less powerful serialization methods, such as JSON or XML.\n\n"
52-
+ "If using safer APIs is difficult and content that is processed is not user content,"
53-
+ " add ise-hardening-reviews as a reviewer for a suppression annotation.",
54-
severity = SeverityLevel.ERROR,
55-
suppressionAnnotations = {
56-
SuppressBanSerializableCompletedSecurityReview.class,
57-
SuppressBanSerializableForLegacyCode.class
58-
})
41+
severity = SeverityLevel.ERROR)
5942
public final class BanSerializableRead extends BugChecker implements MethodInvocationTreeMatcher {
6043

6144
private static final Matcher<ExpressionTree> EXEMPT =
@@ -111,14 +94,8 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
11194
return Description.NO_MATCH;
11295
}
11396

114-
Optional<SuggestedFix> fix =
115-
SuggestedFixes.suggestExemptingAnnotation(
116-
SuppressBanSerializableForLegacyCode.class.getName(), state.getPath(), state);
97+
Description.Builder description = buildDescription(tree);
11798

118-
if (!fix.isPresent()) {
119-
return describeMatch(tree);
120-
}
121-
122-
return describeMatch(tree, fix.get());
99+
return description.build();
123100
}
124101
}

core/src/test/java/com/google/errorprone/bugpatterns/BanSerializableReadTest.java

-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.google.errorprone.bugpatterns;
1818

1919
import com.google.errorprone.BugCheckerRefactoringTestHelper;
20-
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
2120
import com.google.errorprone.CompilationTestHelper;
2221
import org.junit.Test;
2322
import org.junit.runner.RunWith;
@@ -50,12 +49,4 @@ public void testNegativeCaseUnchanged() {
5049
.setArgs("-XepCompilingTestOnlyCode")
5150
.doTest();
5251
}
53-
54-
@Test
55-
public void testRefactor() {
56-
refactoringHelper
57-
.addInput("BanSerializableReadPositiveCases.java")
58-
.addOutput("BanSerializableReadPositiveCases_expected.java")
59-
.doTest(TestMode.TEXT_MATCH);
60-
}
6152
}

core/src/test/java/com/google/errorprone/bugpatterns/testdata/BanSerializableReadNegativeCases.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package com.google.errorprone.bugpatterns.testdata;
1818

19-
import com.google.errorprone.annotations.SuppressBanSerializableCompletedSecurityReview;
20-
import com.google.errorprone.annotations.SuppressBanSerializableForLegacyCode;
2119
import com.google.errorprone.bugpatterns.BanSerializableReadTest;
2220
import java.io.IOException;
2321
import java.io.ObjectInputStream;
@@ -49,7 +47,7 @@ public static final void noCrimesHere() {
4947
* @throws IOException
5048
* @throws ClassNotFoundException
5149
*/
52-
@SuppressBanSerializableForLegacyCode
50+
@SuppressWarnings("BanSerializableRead")
5351
public static final void directCall() throws IOException, ClassNotFoundException {
5452
PipedInputStream in = new PipedInputStream();
5553
PipedOutputStream out = new PipedOutputStream(in);
@@ -68,7 +66,7 @@ public static final void directCall() throws IOException, ClassNotFoundException
6866
* @throws IOException
6967
* @throws ClassNotFoundException
7068
*/
71-
@SuppressBanSerializableCompletedSecurityReview
69+
@SuppressWarnings("BanSerializableRead")
7270
public static final void sayHi() throws IOException, ClassNotFoundException {
7371
PipedInputStream in = new PipedInputStream();
7472
PipedOutputStream out = new PipedOutputStream(in);
@@ -87,7 +85,7 @@ public static final void sayHi() throws IOException, ClassNotFoundException {
8785
// These test the more esoteric annotations
8886

8987
// code has gone through a security review
90-
@SuppressBanSerializableCompletedSecurityReview
88+
@SuppressWarnings("BanSerializableRead")
9189
public static final void directCall2() throws IOException, ClassNotFoundException {
9290
PipedInputStream in = new PipedInputStream();
9391
PipedOutputStream out = new PipedOutputStream(in);
@@ -100,7 +98,7 @@ public static final void directCall2() throws IOException, ClassNotFoundExceptio
10098
}
10199

102100
// code is well-tested legacy
103-
@SuppressBanSerializableForLegacyCode
101+
@SuppressWarnings("BanSerializableRead")
104102
public static final void directCall3() throws IOException, ClassNotFoundException {
105103
PipedInputStream in = new PipedInputStream();
106104
PipedOutputStream out = new PipedOutputStream(in);

core/src/test/java/com/google/errorprone/bugpatterns/testdata/BanSerializableReadPositiveCases_expected.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.errorprone.bugpatterns.testdata;
1818

19-
import com.google.errorprone.annotations.SuppressBanSerializableForLegacyCode;
2019
import com.google.errorprone.bugpatterns.BanSerializableReadTest;
2120
import java.io.IOException;
2221
import java.io.ObjectInputStream;
@@ -39,7 +38,7 @@ class BanSerializableReadPositiveCases implements Serializable {
3938
* @throws IOException
4039
* @throws ClassNotFoundException
4140
*/
42-
@SuppressBanSerializableForLegacyCode
41+
@SuppressWarnings("BanSerializableRead")
4342
public static final void sayHi() throws IOException, ClassNotFoundException {
4443
PipedInputStream in = new PipedInputStream();
4544
PipedOutputStream out = new PipedOutputStream(in);
@@ -64,7 +63,7 @@ public static final void sayHi() throws IOException, ClassNotFoundException {
6463
* @throws IOException
6564
* @throws ClassNotFoundException
6665
*/
67-
@SuppressBanSerializableForLegacyCode
66+
@SuppressWarnings("BanSerializableRead")
6867
public static final void directCall() throws IOException, ClassNotFoundException {
6968
PipedInputStream in = new PipedInputStream();
7069
PipedOutputStream out = new PipedOutputStream(in);
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The Java `Serializable` API is very powerful, and very dangerous. Any
2+
consumption of a serialized object that cannot be explicitly trusted will likely
3+
result in a critical remote code execution bug that will give an attacker
4+
control of the application. (See
5+
[Effective Java 3rd Edition §84][ej3e-84])
6+
7+
Consider using less powerful serialization methods, such as JSON or XML.
8+
9+
[ej3e-84]: https://books.google.com/books?id=BIpDDwAAQBAJ

0 commit comments

Comments
 (0)