Validate E164's in ContactRecords.

This commit is contained in:
Greyson Parrelli
2023-02-23 17:45:20 -05:00
committed by Nicholas Tinsley
parent 33828439fb
commit 8334db5273
2 changed files with 112 additions and 0 deletions

View File

@@ -28,11 +28,14 @@ import java.util.Objects;
import java.util.Optional;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.regex.Pattern;
public class ContactRecordProcessor extends DefaultStorageRecordProcessor<SignalContactRecord> {
private static final String TAG = Log.tag(ContactRecordProcessor.class);
private static final Pattern E164_PATTERN = Pattern.compile("^\\+[1-9]\\d{0,18}$");
private final RecipientTable recipientTable;
private final ACI selfAci;
@@ -141,6 +144,9 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
} else if (!FeatureFlags.phoneNumberPrivacy() && remote.getServiceId().equals(remote.getPni().orElse(null))) {
Log.w(TAG, "Found a PNI-only ContactRecord when PNP is disabled -- marking as invalid.");
return true;
} else if (remote.getNumber().isPresent() && !isValidE164(remote.getNumber().get())) {
Log.w(TAG, "Found a record with an invalid E164. Marking as invalid.");
return true;
} else {
return false;
}
@@ -321,6 +327,10 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
}
}
private static boolean isValidE164(String value) {
return E164_PATTERN.matcher(value).matches();
}
private static boolean doParamsMatch(@NonNull SignalContactRecord contact,
@Nullable byte[] unknownFields,
@NonNull ServiceId serviceId,