Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cdp): add ip anon transformation #28377

Merged
merged 5 commits into from
Feb 6, 2025

Conversation

meikelmosby
Copy link
Contributor

@meikelmosby meikelmosby commented Feb 6, 2025

Problem

We want to offer the same (or better) transformations as competitors.
IP anonymization transformation but uses string splitting instead of regex for performance.

Changes

  • added IPv4 anonymization hog transformation
Screenshot 2025-02-06 at 15 02 46

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

How did you test this code?

  • added tests

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Added IP anonymization transformation to replace the last octet of IPv4 addresses with zero, enhancing user privacy in PostHog's CDP functionality.

  • Added ip-anonymization.template.ts with string splitting for efficient IPv4 anonymization (e.g., 192.168.1.1 → 192.168.1.0)
  • Implemented comprehensive test suite in ip-anonymization.template.test.ts covering valid/invalid IPs and edge cases
  • Integrated template into HOG_FUNCTION_TEMPLATES_TRANSFORMATIONS array in index.ts
  • Template marked as 'alpha' status with clear description and free availability
  • Missing IPv6 support and potential edge case handling for malformed IP strings

3 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile

}

let ip := event.properties.$ip
let parts := splitByString('.', ip)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: No validation of IP address octets. Values like '999.999.999.999' or 'a.b.c.d' will be processed as valid IPs if they contain 4 parts.

Suggested change
let parts := splitByString('.', ip)
let parts := splitByString('.', ip)
// Validate each octet is a number between 0-255
if (length(parts) = 4 and all(x -> toInt(x) >= 0 and toInt(x) <= 255, parts)) {

Comment on lines +20 to +21
let ip := event.properties.$ip
let parts := splitByString('.', ip)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider trimming the IP string to handle whitespace in input

Copy link
Contributor

@benjackwhite benjackwhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good with a small comment

Copy link
Contributor

@benjackwhite benjackwhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually really like the bots suggestions but approved as its not blocking

meikelmosby and others added 3 commits February 6, 2025 15:19
…ion/ip-anonymization.template.test.ts

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@meikelmosby meikelmosby merged commit db9397e into master Feb 6, 2025
96 checks passed
@meikelmosby meikelmosby deleted the feat/cdp/add-ip-anonymization-transformation branch February 6, 2025 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants