Skip to content

Commit ca978f3

Browse files
authored
feat(quotas): Project abuse limit for attachment items (#82155)
Attachment quotas and rate limits are currently defined in bytes, so we have no way to prevent an abusively high number of very small attachments. No abuse limit will be set by default.
1 parent da5ebee commit ca978f3

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/sentry/options/defaults.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,12 @@
12211221
default=0,
12221222
flags=FLAG_PRIORITIZE_DISK | FLAG_AUTOMATOR_MODIFIABLE,
12231223
)
1224+
register(
1225+
"project-abuse-quota.attachment-item-limit",
1226+
type=Int,
1227+
default=0,
1228+
flags=FLAG_PRIORITIZE_DISK | FLAG_AUTOMATOR_MODIFIABLE,
1229+
)
12241230
register(
12251231
"project-abuse-quota.session-limit",
12261232
type=Int,

src/sentry/quotas/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,12 @@ def get_abuse_quotas(self, org):
457457
categories=[DataCategory.ATTACHMENT],
458458
scope=QuotaScope.PROJECT,
459459
),
460+
AbuseQuota(
461+
id="paai",
462+
option="project-abuse-quota.attachment-item-limit",
463+
categories=[DataCategory.ATTACHMENT_ITEM],
464+
scope=QuotaScope.PROJECT,
465+
),
460466
AbuseQuota(
461467
id="pas",
462468
option="project-abuse-quota.session-limit",

tests/sentry/quotas/test_redis.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def test_abuse_quotas(self):
116116

117117
self.organization.update_option("project-abuse-quota.transaction-limit", 600)
118118
self.organization.update_option("project-abuse-quota.attachment-limit", 601)
119+
self.organization.update_option("project-abuse-quota.attachment-item-limit", 6010)
119120
self.organization.update_option("project-abuse-quota.session-limit", 602)
120121
self.organization.update_option("organization-abuse-quota.metric-bucket-limit", 603)
121122
self.organization.update_option("organization-abuse-quota.custom-metric-bucket-limit", 604)
@@ -145,22 +146,30 @@ def test_abuse_quotas(self):
145146
assert quotas[2].window == 10
146147
assert quotas[2].reason_code == "project_abuse_limit"
147148

148-
assert quotas[3].id == "pas"
149+
assert quotas[3].id == "paai"
149150
assert quotas[3].scope == QuotaScope.PROJECT
150151
assert quotas[3].scope_id is None
151-
assert quotas[3].categories == {DataCategory.SESSION}
152-
assert quotas[3].limit == 6020
152+
assert quotas[3].categories == {DataCategory.ATTACHMENT_ITEM}
153+
assert quotas[3].limit == 60100
153154
assert quotas[3].window == 10
154155
assert quotas[3].reason_code == "project_abuse_limit"
155156

156-
assert quotas[4].id == "paspi"
157+
assert quotas[4].id == "pas"
157158
assert quotas[4].scope == QuotaScope.PROJECT
158159
assert quotas[4].scope_id is None
159-
assert quotas[4].categories == {DataCategory.SPAN_INDEXED}
160-
assert quotas[4].limit == 6050
160+
assert quotas[4].categories == {DataCategory.SESSION}
161+
assert quotas[4].limit == 6020
161162
assert quotas[4].window == 10
162163
assert quotas[4].reason_code == "project_abuse_limit"
163164

165+
assert quotas[5].id == "paspi"
166+
assert quotas[5].scope == QuotaScope.PROJECT
167+
assert quotas[5].scope_id is None
168+
assert quotas[5].categories == {DataCategory.SPAN_INDEXED}
169+
assert quotas[5].limit == 6050
170+
assert quotas[5].window == 10
171+
assert quotas[5].reason_code == "project_abuse_limit"
172+
164173
expected_quotas: dict[tuple[QuotaScope, UseCaseID | None], str] = dict()
165174
for scope, prefix in [
166175
(QuotaScope.PROJECT, "p"),

0 commit comments

Comments
 (0)