-
Notifications
You must be signed in to change notification settings - Fork 112
feat(attachment): Add verification logic for attachment placeholders #5747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tobias-wilfert
merged 22 commits into
master
from
tobias-wilfert/feat/envelope-placeholder
Mar 31, 2026
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
84eb00e
correctly handle attachment references in the stores
tobias-wilfert 0d39672
assert`stored_key` is none before it is set
tobias-wilfert 15c8294
add happy path test
tobias-wilfert 12da644
fix test (broke due to me adding `relay-new-error-processing`)
tobias-wilfert e246ebe
add validation logic
tobias-wilfert a3db734
add test for validation logic and update ratelimit test
tobias-wilfert 51f3560
appease clippy
tobias-wilfert 119e4df
Merge branch 'master' into tobias-wilfert/feat/envelope-placeholder
tobias-wilfert 7b90e97
use `application/vnd.sentry.attachment-ref+json`
tobias-wilfert efaa253
use `verify` in store to get key
tobias-wilfert 6fcb34d
use post + patch in test helper
tobias-wilfert fab22b8
add changelog entry
tobias-wilfert dec60e7
Update relay-server/src/services/objectstore.rs
tobias-wilfert 6612cb3
Update relay-server/src/services/outcome.rs
tobias-wilfert 0dd5dd5
Update relay-server/src/processing/attachments/process.rs
tobias-wilfert 56171c9
Update relay-server/src/processing/utils/attachments.rs
tobias-wilfert caea42d
Merge branch 'master' into tobias-wilfert/feat/envelope-placeholder
tobias-wilfert 8033ed8
Merge branch 'tobias-wilfert/feat/envelope-placeholder' of github.com…
tobias-wilfert 688ebaa
add org id
tobias-wilfert 1345053
add correct import
tobias-wilfert ab7163b
move `#[cfg(feature = "processing")]` into validate function
tobias-wilfert d2d48f6
extract common logic for `produce_attachment`
tobias-wilfert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -445,3 +445,24 @@ impl Counted for IndexedSpans { | |
| smallvec![(DataCategory::SpanIndexed, self.0)] | ||
| } | ||
| } | ||
|
|
||
| /// Validates the attachments and drop any invalid ones. | ||
| /// | ||
| /// An attachment might be a placeholder, in which case it needs to be validated. | ||
| pub fn validate_attachments(transaction: &mut Managed<Box<ExpandedTransaction>>, ctx: Context<'_>) { | ||
| if !ctx.is_processing() { | ||
| return; | ||
| } | ||
|
|
||
| transaction.modify(|transaction, records| { | ||
| transaction.attachments.retain_mut(|attachment| { | ||
| match utils::attachments::validate(attachment, ctx.config) { | ||
| Ok(()) => true, | ||
| Err(err) => { | ||
| records.reject_err(err, &*attachment); | ||
| false | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
Comment on lines
+452
to
+468
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like it should be possible to generalize this function, something like fn validate_attachments<T, F>(parent: T, getter: F, ctx: Context<'_>)
where
T: Managed,
F: FnOnce(&mut T) -> &mut impl RetainMut<Item>
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it is ok I would do that in a follow up once we have the |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Placeholder deserialization rejects non-enum content types
Medium Severity
The
content_typefield inAttachmentPlaceholderisOption<ContentType>, butContentTypeis an enum that only supports a small set of known MIME types (e.g.,text/plain,application/json,application/octet-stream). Whenserde_json::from_sliceencounters an unrecognized content type string like"image/png"or"application/pdf", deserialization of the entire placeholder fails, causing the attachment to be rejected as invalid. Regular attachments accept any content type viaraw_content_type()as a free-form string. UsingOption<String>here would be consistent with how regular attachments handle content types.Additional Locations (2)
relay-server/src/processing/utils/attachments.rs#L22-L25relay-server/src/services/store.rs#L975-L978There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true, but it's an issue that may have been introduced by #5671. So I wouldn't change it in this PR.