Skip to content

Commit

Permalink
fix(profiling): Correctly validate typescript profiles (#1283)
Browse files Browse the repository at this point in the history
Need to check the profile key is a non empty array instead.
  • Loading branch information
Zylphrex authored Jun 1, 2022
1 parent 7c6b308 commit 904625c
Show file tree
Hide file tree
Showing 3 changed files with 10,878 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Emit specific event type tags for "processing.event.produced" metric. ([#1270](https://github.com/getsentry/relay/pull/1270))
- Add support for profile outcomes. ([#1272](https://github.com/getsentry/relay/pull/1272))
- Avoid potential panics when scrubbing minidumps. ([#1282](https://github.com/getsentry/relay/pull/1282))
- Fix typescript profile validation. ([#1283](https://github.com/getsentry/relay/pull/1283))

## 22.5.0

Expand Down
45 changes: 43 additions & 2 deletions relay-server/src/utils/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,37 @@ pub fn parse_cocoa_profile(item: &mut Item) -> Result<(), ProfileError> {
Ok(())
}

#[derive(Debug, Serialize, Deserialize)]
struct TypescriptProfile {
device_is_emulator: bool,
device_locale: String,
device_manufacturer: String,
device_model: String,
device_os_build_number: Option<String>,
device_os_name: String,
device_os_version: String,

#[serde(deserialize_with = "deserialize_number_from_string")]
duration_ns: u64,

#[serde(default, skip_serializing_if = "String::is_empty")]
environment: String,

platform: String,
profile_id: EventId,
profile: Vec<serde_json::Value>,
trace_id: EventId,
transaction_id: EventId,
transaction_name: String,
version_code: String,
version_name: String,
}

pub fn parse_typescript_profile(item: &mut Item) -> Result<(), ProfileError> {
let profile: Vec<serde_json::Value> =
let profile: TypescriptProfile =
serde_json::from_slice(&item.payload()).map_err(ProfileError::InvalidJson)?;
if profile.is_empty() {

if profile.profile.is_empty() {
return Err(ProfileError::NotEnoughSamples);
}

Expand Down Expand Up @@ -299,6 +326,20 @@ mod tests {
assert!(parse_android_profile(&mut item).is_ok());
}

#[test]
fn test_roundtrip_typescript() {
let mut item = Item::new(ItemType::Profile);
let payload =
Bytes::from(&include_bytes!("../../tests/fixtures/profiles/typescript.json")[..]);
item.set_payload(ContentType::Json, payload);

assert!(parse_typescript_profile(&mut item).is_ok());

item.set_payload(ContentType::Json, item.payload());

assert!(parse_typescript_profile(&mut item).is_ok());
}

#[test]
fn test_debug_image_compatibility() {
let image_json = r#"{"debug_id":"32420279-25E2-34E6-8BC7-8A006A8F2425","image_addr":"0x000000010258c000","code_file":"/private/var/containers/Bundle/Application/C3511752-DD67-4FE8-9DA2-ACE18ADFAA61/TrendingMovies.app/TrendingMovies","type":"macho","image_size":1720320,"image_vmaddr":"0x0000000100000000"}"#;
Expand Down
Loading

0 comments on commit 904625c

Please sign in to comment.