Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(replay-anonymizer): stop collecting avif images (#116876)

Nicholas Waltz533dff861373
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index a662d1eea34d..4065bd4577cf 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -9553,7 +9553,7 @@ dependencies = [
[[package]]
name = "posthog-replay-anonymizer"
-version = "0.9.0"
+version = "0.9.1"
dependencies = [
"ahash 0.8.12",
"anyhow",
diff --git a/rust/replay-anonymizer/Cargo.toml b/rust/replay-anonymizer/Cargo.toml
index 51db8f1edc40..45b9b1070c51 100644
--- a/rust/replay-anonymizer/Cargo.toml
+++ b/rust/replay-anonymizer/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "posthog-replay-anonymizer"
-version = "0.9.0"
+version = "0.9.1"
edition = "2021"
description = "PII scrubber for rrweb session-replay events: text/URL redaction, native image blur, and canvas/cv neutralization"
license = "MIT"
diff --git a/rust/replay-anonymizer/src/collect.rs b/rust/replay-anonymizer/src/collect.rs
index 4660f325b500..29dc2f2f1391 100644
--- a/rust/replay-anonymizer/src/collect.rs
+++ b/rust/replay-anonymizer/src/collect.rs
@@ -237,13 +237,7 @@ impl ImageCollector {
/// subtypes, parameters — where client-controlled text could ride through unscrubbed) normalizes
/// to `image/png`. Exact matches only: the old blur path re-encoded and overwrote this field, so
/// no client string ever survived; the ref path must not weaken that.
-const COLLECTED_MIME_ALLOWLIST: &[&str] = &[
- "image/png",
- "image/jpeg",
- "image/gif",
- "image/webp",
- "image/avif",
-];
+const COLLECTED_MIME_ALLOWLIST: &[&str] = &["image/png", "image/jpeg", "image/gif", "image/webp"];
pub fn normalize_collected_mime(mime: &str) -> &'static str {
let lower = mime.trim().to_ascii_lowercase();
@@ -268,7 +262,8 @@ pub fn collectable_data_uri_bytes(uri: &str, max_image_bytes: usize) -> Option<V
let mime_type = meta
.split_once(';')
.map_or(meta.as_str(), |(mime_type, _)| mime_type);
- if mime_type.starts_with("image/svg") || mime_type.contains("bmp") {
+ if mime_type.starts_with("image/svg") || mime_type.contains("bmp") || mime_type.contains("avif")
+ {
return None;
}
// An encoded payload that can't decode under the per-image cap would be decoded here only to
@@ -280,7 +275,8 @@ pub fn collectable_data_uri_bytes(uri: &str, max_image_bytes: usize) -> Option<V
let bytes = base64::engine::general_purpose::STANDARD
.decode(payload.as_bytes())
.ok()?;
- if bytes.starts_with(b"BM") {
+ // An ISO-BMFF container (AVIF, HEIC) under any label: the scrub refuses it, so a ref would dangle.
+ if bytes.starts_with(b"BM") || bytes.get(4..8) == Some(b"ftyp") {
return None;
}
Some(bytes)
@@ -383,6 +379,9 @@ mod tests {
assert!(collectable("data:image/bmp;base64,Qk0=").is_none());
assert!(collectable("data:image/x-bmp;base64,Qk0=").is_none());
assert!(collectable("data:image/x-ms-bmp;base64,Qk0=").is_none());
+ assert!(collectable("data:image/avif;base64,AAAAHGZ0eXBhdmlm").is_none());
+ // AVIF bytes behind a raster label.
+ assert!(collectable("data:image/png;base64,AAAAHGZ0eXBhdmlm").is_none());
assert!(collectable("data:image/png;base64,Qk0=").is_none());
assert!(collectable("data:image/svg+xml;utf8,<svg/>").is_none());
assert!(collectable("data:text/plain;base64,aGk=").is_none());