Skip to content

Commit

Permalink
Display Validation ResponseErrors
Browse files Browse the repository at this point in the history
These errors are enumerated and not subject to the kinds of phishing
attacks Unrecognized errors are. Downstream implementations may
choose to display these in e.g. a CLI environment.

Only the Unrecognized errors MUST be swallowed because their
contents are defined by the counterparty.
  • Loading branch information
DanGould committed Jan 7, 2025
1 parent e26df28 commit 27f4cb9
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions payjoin/src/send/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ pub enum ResponseError {
WellKnown(WellKnownError),

/// Errors caused by malformed responses.
///
/// These errors are only displayed in debug logs.
Validation(ValidationError),

/// `Unrecognized` Errors are NOT defined in the [`BIP78::ReceiverWellKnownError`] spec.
Expand Down Expand Up @@ -348,7 +346,7 @@ impl Display for ResponseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::WellKnown(e) => e.fmt(f),
Self::Validation(_) => write!(f, "The receiver sent an invalid response."),
Self::Validation(e) => write!(f, "The receiver sent an invalid response: {}", e),

// Do NOT display unrecognized errors to end users, only debug logs
Self::Unrecognized { .. } => write!(f, "The receiver sent an unrecognized error."),
Expand Down Expand Up @@ -444,9 +442,9 @@ mod tests {
"err": "random",
"message": "This version of payjoin is not supported."
});
assert_eq!(
ResponseError::from_json(invalid_json_error).to_string(),
"The receiver sent an invalid response."
);
assert!(matches!(
ResponseError::from_json(invalid_json_error),
ResponseError::Validation(_)
));
}
}

0 comments on commit 27f4cb9

Please sign in to comment.