Skip to content

Commit

Permalink
feat(demotion_monitor): use safer escape_str
Browse files Browse the repository at this point in the history
  • Loading branch information
alextes committed Nov 29, 2024
1 parent bddeb5e commit da07283
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
16 changes: 0 additions & 16 deletions src/phoenix/alerts/telegram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,6 @@ pub fn escape_str(input: &str) -> String {
output
}

// Used to escape characters inside markdown code blocks
// https://core.telegram.org/bots/api#markdownv2-style
pub fn escape_code_block(input: &str) -> String {
let mut output = String::new();
for c in input.chars() {
match c {
'`' | '\\' => {
output.push('\\');
}
_ => {}
}
output.push(c);
}
output
}

/// Formats a message to be compatible with the Telegram bot API.
/// Respect escaping as described in: https://core.telegram.org/bots/api#markdownv2-style
/// Respect character limit of 4096.
Expand Down
3 changes: 2 additions & 1 deletion src/phoenix/demotion_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ fn format_demotion_message(demotion: &BuilderDemotion) -> String {
let builder_id = demotion.builder_id.as_deref().unwrap_or("unknown");
let escaped_builder_id = telegram::escape_str(builder_id);
let builder_pubkey = &demotion.builder_pubkey;
let error = telegram::escape_code_block(&demotion.sim_error);
// it seems escape_code_block is not safe enough here.
let error = telegram::escape_str(&demotion.sim_error);
let slot = &demotion.slot;
let geo = &demotion.geo;
formatdoc!(
Expand Down

0 comments on commit da07283

Please sign in to comment.