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.

feat(replay-anonymizer): raise the default image-scrub cap to 20 mib (#116926)

Nicholas Waltz29851f417f01
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/config.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/config.ts
index a822a52ba290..12a6958ad096 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/config.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/config.ts
@@ -260,7 +260,7 @@ export function getDefaultMlMirrorConfig(): MlMirrorConfig {
SESSION_RECORDING_ML_REDIS_HOST: '',
SESSION_RECORDING_ML_REDIS_PORT: 6379,
SESSION_RECORDING_ML_IMAGE_SCRUB_PRODUCER_ENABLED: false,
- SESSION_RECORDING_ML_IMAGE_SCRUB_MAX_IMAGE_BYTES: 900 * 1024,
+ SESSION_RECORDING_ML_IMAGE_SCRUB_MAX_IMAGE_BYTES: 20 * 1024 * 1024,
SESSION_RECORDING_ML_URL_COLLECTION_ENABLED: false,
SESSION_RECORDING_ML_URL_PRODUCER_ENABLED: false,
SESSION_RECORDING_ML_URL_CRAWL_HISTORY_PRECHECK_ENABLED: true,
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index 7547aa948e8b..71f0f0f6a597 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -9574,7 +9574,7 @@ dependencies = [
[[package]]
name = "posthog-replay-anonymizer"
-version = "0.12.0"
+version = "0.12.1"
dependencies = [
"ahash 0.8.12",
"anyhow",
diff --git a/rust/replay-anonymizer/Cargo.toml b/rust/replay-anonymizer/Cargo.toml
index 1c5d07d212e1..a34ef9186d5f 100644
--- a/rust/replay-anonymizer/Cargo.toml
+++ b/rust/replay-anonymizer/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "posthog-replay-anonymizer"
-version = "0.12.0"
+version = "0.12.1"
edition = "2021"
description = "PII scrubber for rrweb session-replay events: text/URL redaction, image collection for an out-of-band scrub, and canvas/cv neutralization"
license = "MIT"
diff --git a/rust/replay-anonymizer/src/assets.rs b/rust/replay-anonymizer/src/assets.rs
index 12113bc8f392..530cbf164cb2 100644
--- a/rust/replay-anonymizer/src/assets.rs
+++ b/rust/replay-anonymizer/src/assets.rs
@@ -4,7 +4,7 @@ use std::borrow::Cow;
use simd_json::borrowed::{Object, Value};
-use crate::collect::{collectable_data_uri_bytes, is_image_ref_strict};
+use crate::collect::is_image_ref_strict;
use crate::context::{Ctx, ImageSource};
use crate::data_uri::is_image_data_uri;
use crate::data_uri::ImageFallback;
@@ -140,10 +140,8 @@ pub fn has_media_src_attr(attrs: &Object<'_>) -> bool {
pub(crate) fn has_usable_srcset(value: &str, ctx: &Ctx<'_>) -> bool {
(ctx.keeps_image_refs() && is_image_ref_strict(value))
- || candidate_for_scrubbing(value).is_some_and(|url| {
- collectable_data_uri_bytes(url, ctx.max_collected_image_bytes()).is_ok()
- || canonicalize(url).is_some()
- })
+ || candidate_for_scrubbing(value)
+ .is_some_and(|url| ctx.can_collect_image(url) || canonicalize(url).is_some())
}
/// Scrub an inlined-image data URI held in an attribute (a `<canvas>`/`<img>` `rr_dataURL`).
diff --git a/rust/replay-anonymizer/src/collect.rs b/rust/replay-anonymizer/src/collect.rs
index b35d4c0738ae..554541faa62f 100644
--- a/rust/replay-anonymizer/src/collect.rs
+++ b/rust/replay-anonymizer/src/collect.rs
@@ -118,8 +118,9 @@ fn is_ref_hash(hash: &str) -> bool {
.all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_')
}
-/// Default per-image cap. A bigger image is blanked.
-pub const MAX_IMAGE_BYTES: usize = 900 * 1024;
+/// Default per-image cap: the image-scrub consumer and its sidecar refuse decoded images over
+/// 20 MiB, so a bigger image would only dangle as a ref. A bigger image is blanked.
+pub const MAX_IMAGE_BYTES: usize = 20 * 1024 * 1024;
/// Per-message caps bound what one payload can pin in memory and fan out onto the scrub topic.
/// Capture refuses messages over 64 MB, so the byte cap only binds on a payload that cv nesting
/// expanded past that. Collection peaks at about twice the byte cap per in-flight message
@@ -363,7 +364,9 @@ mod tests {
c.collect(vec![0u8; MAX_IMAGE_BYTES + 1]),
Err(DROP_TOO_LARGE)
);
- assert!(c.into_images().is_empty());
+ // A 1 MiB image is within the default cap.
+ assert!(c.collect(vec![1u8; 1024 * 1024]).is_ok());
+ assert_eq!(c.into_images().len(), 1);
}
#[test]
diff --git a/rust/replay-anonymizer/src/context.rs b/rust/replay-anonymizer/src/context.rs
index f869c16642ad..483228bf46ce 100644
--- a/rust/replay-anonymizer/src/context.rs
+++ b/rust/replay-anonymizer/src/context.rs
@@ -344,12 +344,12 @@ impl<'a> Ctx<'a> {
outcome
}
- pub(crate) fn max_collected_image_bytes(&self) -> usize {
- self.collector
- .as_ref()
- .map_or(MAX_IMAGE_BYTES, |collector| {
- collector.borrow().max_image_bytes()
- })
+ /// Memoized when the lane is on, so the scrub that follows reuses this decode.
+ pub(crate) fn can_collect_image(&self, original: &str) -> bool {
+ match self.collector {
+ Some(_) => self.collect_image(original).is_ok(),
+ None => collectable_data_uri_bytes(original, MAX_IMAGE_BYTES).is_ok(),
+ }
}
}
diff --git a/rust/replay-anonymizer/tests/snapshot.rs b/rust/replay-anonymizer/tests/snapshot.rs
index 21417d6d1d04..4c45f45bfe73 100644
--- a/rust/replay-anonymizer/tests/snapshot.rs
+++ b/rust/replay-anonymizer/tests/snapshot.rs
@@ -984,6 +984,48 @@ fn both_engines_count_and_collect_an_image_once_or_not_at_all() {
}
}
+#[test]
+fn a_srcset_that_fails_to_decode_keeps_the_src_image() {
+ let allow = AllowLists::new(Vec::<String>::new(), Vec::<String>::new());
+ // A valid PNG header, then a payload that does not decode.
+ let broken = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA%%%% 2x";
+ let inner = snapshot_message(json!([{
+ "type": 2,
+ "timestamp": TS0,
+ "data": {
+ "node": {"type": 0, "childNodes": [
+ {"type": 2, "tagName": "img", "attributes": {
+ "src": format!("data:image/png;base64,{COLLECT_PNG_B64}"),
+ "srcset": broken,
+ }, "childNodes": []}
+ ]},
+ "initialOffset": {"top": 0, "left": 0}
+ }
+ }]));
+ for byte_walk in [true, false] {
+ let mut bytes = payload_of(&inner).into_bytes();
+ let out = anonymize_kafka_payload_opts(
+ &allow,
+ &mut bytes,
+ AnonymizeOpts {
+ byte_walk,
+ ..Default::default()
+ },
+ Some(ImageCollection::new(
+ "42".to_string(),
+ "fedcba9876543210fedcba9876543210".to_string(),
+ )),
+ )
+ .expect("anonymizes");
+ assert_eq!(out.meta.images.len(), 1, "walk={byte_walk}");
+ let lines = String::from_utf8(out.lines.clone()).unwrap();
+ assert!(
+ lines.contains("\"src\":\"image:42:"),
+ "walk={byte_walk}: {lines}"
+ );
+ }
+}
+
#[test]
fn image_collection_replaces_images_with_refs_and_returns_the_bytes() {
use base64::Engine;