mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-01 09:26:47 +00:00
Use the target device's registration ID in the GET /v1/keys/identifier/deviceId ratelimit
This commit is contained in:
1 parent
b76eaa1098
commit
4acb3b5ac7
2 files changed
+30
-4
No files matched your search
+22
-4
@@ -6,7 +6,6 @@ package org.whispersystems.textsecuregcm.controllers;
|
||||
|
||||
import com.google.common.net.HttpHeaders;
|
||||
import io.dropwizard.auth.Auth;
|
||||
import io.micrometer.core.instrument.DistributionSummary;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import io.micrometer.core.instrument.Tags;
|
||||
@@ -371,9 +370,8 @@ public class KeysController {
|
||||
final Account target = maybeTarget.orElseThrow(NotFoundException::new);
|
||||
|
||||
if (account.isPresent()) {
|
||||
rateLimiters.getPreKeysLimiter().validate(
|
||||
account.get().getUuid() + "." + maybeAuthenticatedDevice.get().deviceId() + "__" + targetIdentifier.uuid()
|
||||
+ "." + deviceId);
|
||||
rateLimiters.getPreKeysLimiter().validate(getPreKeysLimiterKey(account.get(), maybeAuthenticatedDevice.get(),
|
||||
targetIdentifier, target, deviceId));
|
||||
}
|
||||
|
||||
final List<Device> devices = parseDeviceId(deviceId, target);
|
||||
@@ -409,4 +407,24 @@ public class KeysController {
|
||||
throw new WebApplicationException(Response.status(422).build());
|
||||
}
|
||||
}
|
||||
|
||||
private String getPreKeysLimiterKey(
|
||||
final Account account,
|
||||
final AuthenticatedDevice authenticatedDevice,
|
||||
final ServiceIdentifier targetIdentifier,
|
||||
final Account targetAccount,
|
||||
final String targetDeviceId) {
|
||||
final String targetRegistrationId = targetDeviceId.equals("*")
|
||||
? "*"
|
||||
: String.valueOf(
|
||||
parseDeviceId(targetDeviceId, targetAccount).getFirst().getRegistrationId(targetIdentifier.identityType()));
|
||||
|
||||
return String.format("%s.%s__%s.%s.%s",
|
||||
account.getUuid(),
|
||||
authenticatedDevice.deviceId(),
|
||||
targetIdentifier.uuid(),
|
||||
targetDeviceId,
|
||||
targetRegistrationId
|
||||
);
|
||||
}
|
||||
}
|
||||
+8
@@ -371,8 +371,16 @@ class KeysControllerTest {
|
||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||
.get();
|
||||
|
||||
final String expectedRatelimitKey = String.format("%s.%s__%s.%s.%s",
|
||||
AuthHelper.VALID_UUID,
|
||||
AuthHelper.VALID_DEVICE.getId(),
|
||||
EXISTS_PNI,
|
||||
"*",
|
||||
"*");
|
||||
|
||||
assertThat(result.getStatus()).isEqualTo(429);
|
||||
assertThat(result.getHeaderString("Retry-After")).isEqualTo(String.valueOf(retryAfter.toSeconds()));
|
||||
verify(rateLimiter).validate(expectedRatelimitKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user