Skip to content

Commit 2e2ea4f

Browse files
fix(domain-fronting): guard fallback JSON extraction
Reject malformed fallback relay responses where JSON brace positions are inverted instead of slicing with invalid bounds.
1 parent d56ddc6 commit 2e2ea4f

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/domain_fronter.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,6 +3036,12 @@ impl DomainFronter {
30363036
let end = text.rfind('}').ok_or_else(|| {
30373037
FronterError::BadResponse("no json end in tunnel response".into())
30383038
})?;
3039+
if start > end {
3040+
return Err(FronterError::BadResponse(format!(
3041+
"no valid json object in: {}",
3042+
&text.chars().take(200).collect::<String>()
3043+
)));
3044+
}
30393045
&text[start..=end]
30403046
};
30413047
Ok(serde_json::from_str(json_str)?)
@@ -3204,6 +3210,12 @@ impl DomainFronter {
32043210
let end = text.rfind('}').ok_or_else(|| {
32053211
FronterError::BadResponse("no json end in batch response".into())
32063212
})?;
3213+
if start > end {
3214+
return Err(FronterError::BadResponse(format!(
3215+
"no valid json object in: {}",
3216+
&text.chars().take(200).collect::<String>()
3217+
)));
3218+
}
32073219
&text[start..=end]
32083220
};
32093221
// Don't log payload content. Batch responses carry base64-encoded
@@ -4580,6 +4592,12 @@ fn parse_relay_json(body: &[u8]) -> Result<Vec<u8>, FronterError> {
45804592
&text.chars().take(200).collect::<String>()
45814593
))
45824594
})?;
4595+
if start > end {
4596+
return Err(FronterError::BadResponse(format!(
4597+
"no valid json object in: {}",
4598+
&text.chars().take(200).collect::<String>()
4599+
)));
4600+
}
45834601
serde_json::from_str(&text[start..=end])?
45844602
}
45854603
}

0 commit comments

Comments
 (0)