-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(server): Enforce size limits on UE4 crash reports (#1099)
UE4 crash reports are compressed archives that are unpacked during ingestion in Relay. After expansion, the size of the resulting envelope and its file attachments was never checked, which could pass attachments far exceeding the maximum size limits.
- Loading branch information
Showing
6 changed files
with
85 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use relay_config::Config; | ||
|
||
use crate::envelope::{Envelope, ItemType}; | ||
|
||
/// Checks for size limits of items in this envelope. | ||
/// | ||
/// Returns `true`, if the envelope adheres to the configured size limits. Otherwise, returns | ||
/// `false`, in which case the envelope should be discarded and a `413 Payload Too Large` response | ||
/// should be given. | ||
/// | ||
/// The following limits are checked: | ||
/// | ||
/// - `max_event_size` | ||
/// - `max_attachment_size` | ||
/// - `max_attachments_size` | ||
/// - `max_session_count` | ||
pub fn check_envelope_size_limits(config: &Config, envelope: &Envelope) -> bool { | ||
let mut event_size = 0; | ||
let mut attachments_size = 0; | ||
let mut session_count = 0; | ||
let mut client_reports_size = 0; | ||
|
||
for item in envelope.items() { | ||
match item.ty() { | ||
ItemType::Event | ||
| ItemType::Transaction | ||
| ItemType::Security | ||
| ItemType::RawSecurity | ||
| ItemType::FormData => event_size += item.len(), | ||
ItemType::Attachment | ItemType::UnrealReport => { | ||
if item.len() > config.max_attachment_size() { | ||
return false; | ||
} | ||
|
||
attachments_size += item.len() | ||
} | ||
ItemType::Session => session_count += 1, | ||
ItemType::Sessions => session_count += 1, | ||
ItemType::UserReport => (), | ||
ItemType::Metrics => (), | ||
ItemType::MetricBuckets => (), | ||
ItemType::ClientReport => client_reports_size += item.len(), | ||
} | ||
} | ||
|
||
event_size <= config.max_event_size() | ||
&& attachments_size <= config.max_attachments_size() | ||
&& session_count <= config.max_session_count() | ||
&& client_reports_size <= config.max_client_reports_size() | ||
} |
This file contains 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