Skip to content

Commit 3b6857e

Browse files
jpnurmiclaude
andcommitted
feat(attachment): reject attachments larger than 1 GiB
Relay's default `max_upload_size` is 1 GiB — any attachment above that can't be delivered, TUS or inline. Check the size when the attachment is registered and drop oversized ones with a warn log naming the file and the cap. Also add an info log when a large (>= 100 MiB) attachment is attached, so users see that it'll be routed through TUS, and fix the stale `100 MB` unit comment on `SENTRY_LARGE_ATTACHMENT_SIZE` — the value is 100 MiB. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ea673c9 commit 3b6857e

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/sentry_attachment.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "sentry_attachment.h"
22
#include "sentry_alloc.h"
3+
#include "sentry_logger.h"
34
#include "sentry_path.h"
45
#include "sentry_string.h"
56

@@ -158,6 +159,18 @@ sentry__attachments_add(sentry_attachment_t **attachments_ptr,
158159
if (!attachment) {
159160
return NULL;
160161
}
162+
size_t size = sentry__attachment_get_size(attachment);
163+
if (size > SENTRY_MAX_ATTACHMENT_SIZE) {
164+
SENTRY_WARNF("rejected oversized attachment \"%s\" (%zu > %d MiB)",
165+
sentry__attachment_get_filename(attachment), size / (1024 * 1024),
166+
SENTRY_MAX_ATTACHMENT_SIZE / (1024 * 1024));
167+
sentry__attachment_free(attachment);
168+
return NULL;
169+
}
170+
if (size >= SENTRY_LARGE_ATTACHMENT_SIZE) {
171+
SENTRY_INFOF("added large attachment \"%s\" (%zu MiB)",
172+
sentry__attachment_get_filename(attachment), size / (1024 * 1024));
173+
}
161174
attachment->type = attachment_type;
162175
attachment->content_type = sentry__string_clone(content_type);
163176

src/sentry_attachment.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
#include "sentry_path.h"
77

8-
#define SENTRY_LARGE_ATTACHMENT_SIZE (100 * 1024 * 1024) // 100 MB
8+
#define SENTRY_LARGE_ATTACHMENT_SIZE (100 * 1024 * 1024) // 100 MiB
9+
#define SENTRY_MAX_ATTACHMENT_SIZE (1024 * 1024 * 1024) // 1 GiB
910

1011
/**
1112
* The attachment_type.

0 commit comments

Comments
 (0)