Skip to content

Commit c48b8a5

Browse files
committed
CBL-8289: Reject replication filter requests on unexpected errors
* Changed ReplicationCollection filter callback to return false (reject) rather than true (allow) when encountering unexpected error conditions. * Updated comments and log messages.
1 parent 9ca2f1e commit c48b8a5

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

common/main/java/com/couchbase/lite/internal/ReplicationCollection.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,31 @@ static boolean filterCallback(
121121
revID,
122122
collToken,
123123
coll);
124+
125+
// This should never happen. If it does, abort and return false for security reasons.
124126
if (coll == null) {
125-
Log.w(LOG_DOMAIN, "Request to filter unrecognized collection: " + scope + "." + name);
126-
return true;
127+
Log.w(LOG_DOMAIN,
128+
"Rejecting filter request for unrecognized collection %s.%s, returning false",
129+
scope, name);
130+
return false;
127131
}
128132

129133
final C4Filter filter = (isPush) ? coll.c4PushFilter : coll.c4PullFilter;
130-
if (filter == null) { return true; }
131134

132-
// This shouldn't happen.
133-
// If it does, we have no idea what is going on and shouldn't get in the way.
135+
// This should never happen. If it does, abort and return false for security reasons.
136+
if (filter == null) {
137+
Log.w(LOG_DOMAIN,
138+
"Rejecting filter request, %s filter could not be found, returning false",
139+
isPush ? "push" : "pull");
140+
return false;
141+
}
142+
143+
// This should never happen. If it does, abort and return false for security reasons.
134144
if ((docID == null) || (revID == null)) {
135-
Log.w(LOG_DOMAIN, "Ignoring filter request for null %s/%s", docID, revID);
136-
return true;
145+
Log.w(LOG_DOMAIN,
146+
"Rejecting filter request with null docID or revID: %s/%s, returning false",
147+
docID, revID);
148+
return false;
137149
}
138150

139151
final ClientTask<Boolean> task = new ClientTask<>(() -> filter.test(docID, revID, body, flags));

0 commit comments

Comments
 (0)