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(error-tracking): strip release remote credentials from events (#95925)

Hugues Pouillot156c731b97ba
diff --git a/rust/cymbal/src/core/types/frames/releases.rs b/rust/cymbal/src/core/types/frames/releases.rs
index f474dbeced1a..a732758dfb2a 100644
--- a/rust/cymbal/src/core/types/frames/releases.rs
+++ b/rust/cymbal/src/core/types/frames/releases.rs
@@ -129,7 +129,7 @@ impl ReleaseRecord {
project: self.project.clone(),
version: self.version.clone(),
timestamp: self.created_at,
- metadata: self.metadata.clone(),
+ metadata: self.metadata.as_ref().map(sanitize_metadata_for_event),
}
}
@@ -163,6 +163,36 @@ fn truncate_chars(value: &mut String, max_chars: usize) {
}
}
+fn sanitize_metadata_for_event(metadata: &Value) -> Value {
+ let mut sanitized = metadata.clone();
+ if let Some(Value::String(remote_url)) = sanitized.pointer_mut("/git/remote_url") {
+ *remote_url = sanitize_remote_url(remote_url);
+ }
+ sanitized
+}
+
+fn sanitize_remote_url(url: &str) -> String {
+ let sanitized_end = url.find(['?', '#']).unwrap_or(url.len());
+ let Some(scheme_end) = url[..sanitized_end].find("://") else {
+ return url[..sanitized_end].to_string();
+ };
+ let authority_start = scheme_end + 3;
+ let authority_end = url[authority_start..sanitized_end]
+ .find('/')
+ .map_or(sanitized_end, |index| authority_start + index);
+ let authority = &url[authority_start..authority_end];
+ let Some(credentials_end) = authority.rfind('@') else {
+ return url[..sanitized_end].to_string();
+ };
+
+ format!(
+ "{}{}{}",
+ &url[..authority_start],
+ &authority[credentials_end + 1..],
+ &url[authority_end..sanitized_end]
+ )
+}
+
/// Reconstruct the release `hash_id` the CLI wrote for a mobile build, from the app metadata the
/// SDK sends on every event. Mobile events carry no injected `$release_id`, so this is how their
/// release is resolved. It must stay byte-for-byte identical to the CLI, which keys releases on
@@ -296,6 +326,40 @@ mod tests {
}
}
+ #[test]
+ fn event_remote_urls_drop_credentials_query_and_fragment() {
+ let cases = [
+ (
+ "https://user:[email protected]/example/repo.git?token=query#access_token=fragment",
+ "https://github.com/example/repo.git",
+ ),
+ (
+ "https://github.com/example/repo.git#access_token=fragment",
+ "https://github.com/example/repo.git",
+ ),
+ (
+ "https://github.com/example/repo.git",
+ "https://github.com/example/repo.git",
+ ),
+ (
+ "[email protected]:example/repo.git",
+ "[email protected]:example/repo.git",
+ ),
+ (
+ "[email protected]:example/repo.git?token=query#access_token=fragment",
+ "[email protected]:example/repo.git",
+ ),
+ ];
+
+ for (remote_url, expected) in cases {
+ let info = serde_json::to_value(
+ record(Some(json!({"git": {"remote_url": remote_url}}))).to_info(),
+ )
+ .unwrap();
+ assert_eq!(info["metadata"]["git"]["remote_url"], expected);
+ }
+ }
+
#[test]
fn oversized_fields_are_clamped_but_sane_fields_survive() {
// The API does not bound these fields, and each is embedded into every matching event;
diff --git a/rust/cymbal/src/modes/processing/types/exception_event.rs b/rust/cymbal/src/modes/processing/types/exception_event.rs
index 4c99b0e1123a..f9ac3e73680b 100644
--- a/rust/cymbal/src/modes/processing/types/exception_event.rs
+++ b/rust/cymbal/src/modes/processing/types/exception_event.rs
@@ -826,7 +826,7 @@ mod tests {
}
#[test]
- fn exception_release_emitted_only_when_a_release_resolves() {
+ fn exception_release_is_sanitized_and_emitted_only_when_a_release_resolves() {
let issue = Issue {
id: Uuid::now_v7(),
team_id: 42,
@@ -836,7 +836,13 @@ mod tests {
description: None,
created_at: chrono::Utc::now(),
};
- let record = release_record("hash-abc");
+ let mut record = release_record("hash-abc");
+ record.metadata = Some(serde_json::json!({
+ "git": {
+ "commit_id": "abc123",
+ "remote_url": "https://x-access-token:[email protected]/example/repo.git?token=query-secret#access_token=fragment-secret"
+ }
+ }));
let expected = serde_json::to_value(record.to_info()).unwrap();
// A resolved release surfaces as `$exception_release` on both the grouping-rule projection
@@ -845,10 +851,21 @@ mod tests {
resolved.state.metadata.release = Some(record.to_info());
let grouping = resolved.grouping_rule_properties();
assert_eq!(grouping["$exception_release"], expected);
+ assert_eq!(
+ grouping["$exception_release"]["metadata"]["git"],
+ serde_json::json!({
+ "commit_id": "abc123",
+ "remote_url": "https://github.com/example/repo.git"
+ })
+ );
let fingerprinted =
resolved.into_fingerprinted(SelectedFingerprint::manual("fp".to_string()));
let wire = serde_json::to_value(fingerprinted.processed_properties(&issue)).unwrap();
assert_eq!(wire["$exception_release"], expected);
+ assert_eq!(
+ wire["$exception_release"]["metadata"]["git"]["remote_url"],
+ "https://github.com/example/repo.git"
+ );
// No release resolved: the property is omitted.
let mut resolved = resolved_event();