mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 20:58:03 +01:00
Simplify parsing/validation of spam report tokens
This commit is contained in:
committed by
Jon Chambers
parent
48e8584e13
commit
00e08b8402
@@ -643,16 +643,7 @@ public class MessageController {
|
||||
UUID spamReporterUuid = auth.getAccount().getUuid();
|
||||
|
||||
// spam report token is optional, but if provided ensure it is valid base64.
|
||||
byte[] spamReportToken = null;
|
||||
if (spamReport != null) {
|
||||
try {
|
||||
spamReportToken = Base64.getDecoder().decode(spamReport.token());
|
||||
Metrics.counter(REPORT_SPAM_TOKENS_RECEIVED_COUNTER_NAME).increment();
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.error("Invalid report spam token provided", e);
|
||||
throw new WebApplicationException(Response.status(400).build());
|
||||
}
|
||||
}
|
||||
@Nullable final byte[] spamReportToken = spamReport != null ? spamReport.token() : null;
|
||||
|
||||
// fire-and-forget: we don't want to block the response on this action.
|
||||
CompletableFuture<Boolean> ignored =
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package org.whispersystems.textsecuregcm.entities;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import org.whispersystems.textsecuregcm.util.ByteArrayAdapter;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
public record SpamReport(@JsonProperty("token") @NotEmpty String token) {}
|
||||
public record SpamReport(@JsonSerialize(using = ByteArrayAdapter.Serializing.class)
|
||||
@JsonDeserialize(using = ByteArrayAdapter.Deserializing.class)
|
||||
@NotEmpty byte[] token) {}
|
||||
|
||||
Reference in New Issue
Block a user