Skip to content

Commit 464b218

Browse files
chaorenError Prone Team
authored and
Error Prone Team
committed
Implement BanSerializableRead in Android Lint.
PiperOrigin-RevId: 450680744
1 parent 7cd5def commit 464b218

File tree

2 files changed

+45
-23
lines changed

2 files changed

+45
-23
lines changed

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.errorprone.bugpatterns;
1818

19+
import static com.google.errorprone.bugpatterns.SerializableReads.BANNED_OBJECT_INPUT_STREAM_METHODS;
1920
import static com.google.errorprone.matchers.Matchers.allOf;
2021
import static com.google.errorprone.matchers.Matchers.anyOf;
2122
import static com.google.errorprone.matchers.Matchers.enclosingClass;
@@ -25,7 +26,6 @@
2526
import static com.google.errorprone.matchers.Matchers.methodIsNamed;
2627
import static com.google.errorprone.matchers.Matchers.not;
2728

28-
import com.google.common.collect.ImmutableSet;
2929
import com.google.errorprone.BugPattern;
3030
import com.google.errorprone.BugPattern.SeverityLevel;
3131
import com.google.errorprone.VisitorState;
@@ -41,28 +41,6 @@
4141
severity = SeverityLevel.ERROR)
4242
public final class BanSerializableRead extends BugChecker implements MethodInvocationTreeMatcher {
4343

44-
private static final ImmutableSet<String> BANNED_OBJECT_INPUT_STREAM_METHODS =
45-
ImmutableSet.of(
46-
// Prevent reading objects unsafely into memory
47-
"readObject",
48-
49-
// This is the same, the default value
50-
"defaultReadObject",
51-
52-
// This is for trusted subclasses
53-
"readObjectOverride",
54-
55-
// Ultimately, a lot of the safety worries come
56-
// from being able to construct arbitrary classes via
57-
// reading in class descriptors. I don't think anyone
58-
// will bother calling this directly, but I don't see
59-
// any reason not to block it.
60-
"readClassDescriptor",
61-
62-
// These are basically the same as above
63-
"resolveClass",
64-
"resolveObject");
65-
6644
private static final Matcher<ExpressionTree> EXEMPT =
6745
anyOf(
6846
// This is called through ObjectInputStream; a call further up the callstack will have
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2022 The Error Prone Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.errorprone.bugpatterns;
18+
19+
import com.google.common.collect.ImmutableSet;
20+
21+
/** List of banned methods for {@link BanSerializableRead}. */
22+
public final class SerializableReads {
23+
private SerializableReads() {}
24+
25+
public static final ImmutableSet<String> BANNED_OBJECT_INPUT_STREAM_METHODS =
26+
ImmutableSet.of(
27+
// Prevent reading objects unsafely into memory.
28+
"readObject",
29+
30+
// This is the same, the default value.
31+
"defaultReadObject",
32+
33+
// This is for trusted subclasses.
34+
"readObjectOverride",
35+
36+
// Ultimately, a lot of the safety worries come from being able to construct arbitrary
37+
// classes via reading in class descriptors. I don't think anyone will bother calling this
38+
// directly, but I don't see any reason not to block it.
39+
"readClassDescriptor",
40+
41+
// These are basically the same as above.
42+
"resolveClass",
43+
"resolveObject");
44+
}

0 commit comments

Comments
 (0)