Skip to content

fix: strip $session_entry_* URL props (site admin URLs leaking to PostHog)#33

Merged
kilbot merged 3 commits into
mainfrom
fix/strip-session-entry-urls
Jun 15, 2026
Merged

fix: strip $session_entry_* URL props (site admin URLs leaking to PostHog)#33
kilbot merged 3 commits into
mainfrom
fix/strip-session-entry-urls

Conversation

@kilbot

@kilbot kilbot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Found while auditing the live PostHog install (you asked me to confirm useful data is being collected).

Leak: newer posthog-js records the entry URL/referrer/host on a $session_entry_* family, and our before_send only stripped the older $current_url/$host/$pathname/$referrer/$referring_domain. So site admin URLs were reaching PostHog — e.g. $session_entry_url = https://inventory.sopec.net/wp-admin/admin.php?page=woocommerce-pos. 326 events/day carried these.

Fix: strip the whole $session_entry_* family in before_send (no useful campaign data on an admin-screen entry). Test added in tests/analytics-config.test.mjs.

Note: a separate leak exists in the plugin's own PostHog tracking (upgrade_cta_viewed, ~188 events/day with $current_url) which doesn't use this before_send — I'll file that against woocommerce-pos separately.

Leaving unmerged for review.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced analytics event filtering to exclude session-related properties from data collection.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kilbot, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 12 minutes and 22 seconds. Learn how PR review limits work.

To continue reviewing without waiting, enable usage-based billing in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: wcpos/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: bf33e0d1-164c-4f16-b1e4-357d83f2b8e4

📥 Commits

Reviewing files that changed from the base of the PR and between 2878089 and dc03928.

📒 Files selected for processing (3)
  • assets/js/welcome.js
  • src/shared/analytics.ts
  • tests/analytics-config.test.mjs
📝 Walkthrough

Walkthrough

The before_send hook in initAnalytics() is updated to remove all PostHog $session_entry_* properties by iterating over event.properties keys and deleting those with the prefix, replacing the prior explicit deletion of five named URL/referrer fields. One test assertion is added to verify the prefix-check logic.

Changes

Session Entry Property Sanitization

Layer / File(s) Summary
before_send prefix-based removal and test
src/shared/analytics.ts, tests/analytics-config.test.mjs
The fixed set of deleted URL/referrer field names is replaced with a key-iteration loop that removes any property starting with $session_entry_. A new assert.match checks that key.startsWith('$session_entry_') logic is present in the source.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🧹 No more named fields lined up in a row,
A prefix loop now sweeps them all below.
$session_entry_? Gone with a startsWith glance,
The before_send hook leads a cleaner dance.
Less brittle, more broad — the properties flee! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing a privacy issue by stripping $session_entry_* properties from PostHog event payloads to prevent admin URLs from leaking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/strip-session-entry-urls

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/analytics-config.test.mjs`:
- Around line 19-20: The test loop in the for statement on line 19 currently
checks four legacy URL fields but is missing `$referring_domain`, which is also
stripped by the `before_send` function in the actual implementation. Add
`$referring_domain` to the array of keys being validated in the loop to ensure
the test covers all legacy fields that are sanitized by the analytics code.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: wcpos/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 57ffde85-c873-4686-b69a-ac85821acfb0

📥 Commits

Reviewing files that changed from the base of the PR and between 253abc4 and 2878089.

📒 Files selected for processing (3)
  • assets/js/welcome.js
  • src/shared/analytics.ts
  • tests/analytics-config.test.mjs

Comment thread tests/analytics-config.test.mjs Outdated
kilbot added a commit that referenced this pull request Jun 15, 2026
Covers the full legacy URL-field list that before_send sanitizes, keeping
the test aligned with the sanitization contract in analytics.ts.
kilbot added 2 commits June 15, 2026 13:26
… leaking)

PostHog data check on prod found site admin URLs (e.g.
https://shop.example/wp-admin/admin.php?page=woocommerce-pos) reaching PostHog
via the newer posthog-js $session_entry_url/$session_entry_referrer/etc. family
— before_send only stripped the older $current_url/$host/$pathname/$referrer/
$referring_domain. Strip the whole $session_entry_* family too (privacy / wp.org
guideline 7). 326 events/day were carrying these.
Covers the full legacy URL-field list that before_send sanitizes, keeping
the test aligned with the sanitization contract in analytics.ts.
@kilbot kilbot force-pushed the fix/strip-session-entry-urls branch from e86dcba to 6c55817 Compare June 15, 2026 11:26
@kilbot kilbot merged commit edcde21 into main Jun 15, 2026
8 checks passed
@kilbot kilbot deleted the fix/strip-session-entry-urls branch June 15, 2026 11:45
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.

1 participant