Skip to content

Commit

Permalink
instr(csp): Log more info for invalid security reports (#2606)
Browse files Browse the repository at this point in the history
Help us debug invalid security report errors.
  • Loading branch information
jjbayer authored Oct 16, 2023
1 parent a636316 commit e5bc283
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions relay-server/src/actors/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ pub enum ProcessingError {
#[error("missing project id in DSN")]
MissingProjectId,

#[error("invalid security report type")]
InvalidSecurityType,
#[error("invalid security report type: {0:?}")]
InvalidSecurityType(Bytes),

#[error("invalid security report")]
InvalidSecurityReport(#[source] serde_json::Error),
Expand Down Expand Up @@ -147,7 +147,9 @@ impl ProcessingError {
Self::PayloadTooLarge => Some(Outcome::Invalid(DiscardReason::TooLarge)),
Self::InvalidJson(_) => Some(Outcome::Invalid(DiscardReason::InvalidJson)),
Self::InvalidMsgpack(_) => Some(Outcome::Invalid(DiscardReason::InvalidMsgpack)),
Self::InvalidSecurityType => Some(Outcome::Invalid(DiscardReason::SecurityReportType)),
Self::InvalidSecurityType(_) => {
Some(Outcome::Invalid(DiscardReason::SecurityReportType))
}
Self::InvalidSecurityReport(_) => Some(Outcome::Invalid(DiscardReason::SecurityReport)),
Self::InvalidTransaction => Some(Outcome::Invalid(DiscardReason::InvalidTransaction)),
Self::InvalidTimestamp => Some(Outcome::Invalid(DiscardReason::Timestamp)),
Expand Down Expand Up @@ -1435,10 +1437,13 @@ impl EnvelopeProcessorService {
let len = item.len();
let mut event = Event::default();

let data = &item.payload();
let report_type = SecurityReportType::from_json(data)
.map_err(ProcessingError::InvalidJson)?
.ok_or(ProcessingError::InvalidSecurityType)?;
let bytes = item.payload();
let data = &bytes;
let Some(report_type) =
SecurityReportType::from_json(data).map_err(ProcessingError::InvalidJson)?
else {
return Err(ProcessingError::InvalidSecurityType(bytes));
};

let apply_result = match report_type {
SecurityReportType::Csp => Csp::apply_to_event(data, &mut event),
Expand Down

0 comments on commit e5bc283

Please sign in to comment.