Repository navigation
fix(analytics): strip NUL bytes and slim web-analytics payload - #28232
Conversation
PostgreSQL jsonb rejects strings containing the NUL character, which broke PUT /v1/analytics/web/events/collect whenever the UI captured page text containing NULs (e.g. Health Check error messages). Sanitize NUL characters in WebAnalyticEventResource before the jsonb insert. While auditing the path, drop UI fields that have zero downstream consumers: - Remove global document.body click listener; CustomEvent click data is written, kept 7 days, then deleted with no reader. - Trim PageView payload from 9 fields to 4 (userId, sessionId, url, fullUrl); hostname/language/screenSize/referrer/pageLoadTime are never read by any processor. DAU/MAU and Most Viewed Entities reports are unaffected since the WebAnalyticsUserActivityProcessor and WebAnalyticsEntityViewProcessor only read the kept fields. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Fixes a PSQLException triggered when web analytics payloads contained NUL (\u0000) bytes (PostgreSQL jsonb cannot store them) by sanitizing user-supplied string fields on the server. Additionally trims the UI analytics surface area: removes the global document.body click listener (source of the bug) and the now-unused fields from the PageView payload, keeping only what downstream Data Insights processors consume.
Changes:
- Add
removeNullCharacters/stripNullCharactershelpers and apply them toPageViewDataandCustomEventinsidesanitizeWebAnalyticEventData. - Drop the
track/trackCustomEventplugin, the body click listener, and unused helpers (getReferrerPath,getPageLoadTime); reducePageViewpayload touserId,sessionId,url,fullUrl. - Add
WebAnalyticEventResourceTestand refreshWebAnalyticsUtils.test.tsto match the new behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| openmetadata-service/src/main/java/org/openmetadata/service/resources/analytics/WebAnalyticEventResource.java | Strip NUL bytes from PageView and CustomEvent fields before persistence. |
| openmetadata-service/src/test/java/org/openmetadata/service/resources/analytics/WebAnalyticEventResourceTest.java | New unit tests covering NUL stripping and sanitization paths. |
| openmetadata-ui/src/main/resources/ui/src/utils/WebAnalyticsUtils.ts | Slim PageView payload, remove trackCustomEvent and unused helpers. |
| openmetadata-ui/src/main/resources/ui/src/utils/WebAnalyticsUtils.test.ts | Update tests to assert minimal PageView payload and userId guard. |
| openmetadata-ui/src/main/resources/ui/src/components/AppContainer/AppContainer.tsx | Remove global click listener that triggered custom-event tracking. |
Apply stripNullCharacters to every CustomEvent right after the JSON conversion, mirroring the PageView path, so a future CustomEventTypes value cannot silently bypass sanitization. No behavior change today since CLICK is the only enum value and the else branch throws. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
🟡 Playwright Results — all passed (10 flaky)✅ 4139 passed · ❌ 0 failed · 🟡 10 flaky · ⏭️ 89 skipped
🟡 10 flaky test(s) (passed on retry)
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
The unscoped waitForResponse(method === 'PUT') was satisfied by the analytics click handler's PUT /api/v1/analytics/web/events/collect. With that handler removed, the click only opens a dropdown — no PUT fires, so the test hangs until timeout. The actual save is a PATCH already captured by patchRequest.
Code Review ✅ Approved 2 resolved / 2 findingsStrips NUL bytes from analytics payloads to resolve PostgreSQL storage exceptions and minimizes the payload size by removing unused fields. Cleanly addresses all identified sanitization edge cases. ✅ 2 resolved✅ Bug: NUL stripping must happen before HTML check to avoid false negatives
✅ Edge Case: HTML check on eventValue may pass after NUL stripping reassembles tag
OptionsDisplay: compact → Showing less information. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
|
|
* fix(analytics): strip NUL bytes and slim web-analytics payload PostgreSQL jsonb rejects strings containing the NUL character, which broke PUT /v1/analytics/web/events/collect whenever the UI captured page text containing NULs (e.g. Health Check error messages). Sanitize NUL characters in WebAnalyticEventResource before the jsonb insert. While auditing the path, drop UI fields that have zero downstream consumers: - Remove global document.body click listener; CustomEvent click data is written, kept 7 days, then deleted with no reader. - Trim PageView payload from 9 fields to 4 (userId, sessionId, url, fullUrl); hostname/language/screenSize/referrer/pageLoadTime are never read by any processor. DAU/MAU and Most Viewed Entities reports are unaffected since the WebAnalyticsUserActivityProcessor and WebAnalyticsEntityViewProcessor only read the kept fields. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(analytics): hoist NUL strip out of CustomEvent CLICK branch Apply stripNullCharacters to every CustomEvent right after the JSON conversion, mirroring the PageView path, so a future CustomEventTypes value cannot silently bypass sanitization. No behavior change today since CLICK is the only enum value and the else branch throws. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(playwright): drop bogus PUT wait in assignGlossaryTermToChildren The unscoped waitForResponse(method === 'PUT') was satisfied by the analytics click handler's PUT /api/v1/analytics/web/events/collect. With that handler removed, the click only opens a dropdown — no PUT fires, so the test hangs until timeout. The actual save is a PATCH already captured by patchRequest. --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]> Co-authored-by: Siddhant <[email protected]>
Test #8 ("should queue concurrent 401s behind a single refresh call") was passing for the wrong reason. The click on app-bar-item-explore was a no-op (NavLink to the same route), but the document.body click listener in AppContainer.tsx was firing analytics.track on every click anywhere — that PUT to /api/v1/analytics/web/events/collect 401'd, was caught by the in-app axios interceptor, refreshed, and the test happened to see a 200 on /api/v1/auth/refresh. PR #28232 removed that global click listener (it was dead-ended analytics surface area). The hidden trigger is gone, so test #8 has no actual authenticated request to 401 — waitForResponse for /refresh times out. Fix: navigate the user away from /explore (back to /my-data) before the expiry wait, so the subsequent app-bar-item-explore click is a real route change that fires the page's API calls and 401s through the in-app refresh path the test name promises. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…#28322) Test #8 ("should queue concurrent 401s behind a single refresh call") was passing for the wrong reason. The click on app-bar-item-explore was a no-op (NavLink to the same route), but the document.body click listener in AppContainer.tsx was firing analytics.track on every click anywhere — that PUT to /api/v1/analytics/web/events/collect 401'd, was caught by the in-app axios interceptor, refreshed, and the test happened to see a 200 on /api/v1/auth/refresh. PR #28232 removed that global click listener (it was dead-ended analytics surface area). The hidden trigger is gone, so test #8 has no actual authenticated request to 401 — waitForResponse for /refresh times out. Fix: navigate the user away from /explore (back to /my-data) before the expiry wait, so the subsequent app-bar-item-explore click is a real route change that fires the page's API calls and 401s through the in-app refresh path the test name promises. Co-authored-by: Siddhant <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
…#28322) Test #8 ("should queue concurrent 401s behind a single refresh call") was passing for the wrong reason. The click on app-bar-item-explore was a no-op (NavLink to the same route), but the document.body click listener in AppContainer.tsx was firing analytics.track on every click anywhere — that PUT to /api/v1/analytics/web/events/collect 401'd, was caught by the in-app axios interceptor, refreshed, and the test happened to see a 200 on /api/v1/auth/refresh. PR #28232 removed that global click listener (it was dead-ended analytics surface area). The hidden trigger is gone, so test #8 has no actual authenticated request to 401 — waitForResponse for /refresh times out. Fix: navigate the user away from /explore (back to /my-data) before the expiry wait, so the subsequent app-bar-item-explore click is a real route change that fires the page's API calls and 401s through the in-app refresh path the test name promises. Co-authored-by: Siddhant <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]> (cherry picked from commit 533813d)
…#28322) Test #8 ("should queue concurrent 401s behind a single refresh call") was passing for the wrong reason. The click on app-bar-item-explore was a no-op (NavLink to the same route), but the document.body click listener in AppContainer.tsx was firing analytics.track on every click anywhere — that PUT to /api/v1/analytics/web/events/collect 401'd, was caught by the in-app axios interceptor, refreshed, and the test happened to see a 200 on /api/v1/auth/refresh. PR #28232 removed that global click listener (it was dead-ended analytics surface area). The hidden trigger is gone, so test #8 has no actual authenticated request to 401 — waitForResponse for /refresh times out. Fix: navigate the user away from /explore (back to /my-data) before the expiry wait, so the subsequent app-bar-item-explore click is a real route change that fires the page's API calls and 401s through the in-app refresh path the test name promises. Co-authored-by: Siddhant <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]> (cherry picked from commit 533813d)



Describe your changes:
Fix a
PSQLException: unsupported Unicode escape sequenceraised whenPUT /v1/analytics/web/events/collectpayloads contained the NUL character (PostgreSQLjsonbcannot store NUL bytes).WebAnalyticEventResource.sanitizeWebAnalyticEventDatanow strips NULs from all user-supplied string fields on bothPageViewDataandCustomEventbefore the insert. While auditing the path I also trimmed the UI to stop sending fields that no downstream processor reads — removed the globaldocument.bodyclick listener (CustomEvent click data has zero readers; it was the source of the NUL-byte bug and fired on every click) and reduced the PageView payload from 9 fields to 4 (userId,sessionId,url,fullUrl), droppinghostname,language,screenSize,referrer,pageLoadTime. The Data InsightsWebAnalyticsUserActivityProcessorandWebAnalyticsEntityViewProcessoronly read the kept fields, so DAU/MAU and "Most Viewed Entities" reports remain unchanged.Type of change:
Tests:
Unit tests
WebAnalyticEventResourceTest(5 cases): null input, no-NUL fast path, multi-NUL stripping, end-to-end sanitization forPageViewDataandCustomEvent.WebAnalyticsUtils.test.tsto assert the new minimum PageView payload and the userId guard; removed obsoletegetReferrerPath/trackCustomEventcases.Backend integration tests
WebAnalyticEventResourceITcontinues to exercise the endpoint).Playwright (UI) tests
Manual testing performed
mvn test -pl openmetadata-service -Dtest=WebAnalyticEventResourceTest→ 5/5 pass.yarn test WebAnalyticsUtils→ 3/3 pass.mvn spotless:checkandyarn ui-checkstyle:changedboth clean.UI screen recording / screenshots:
Not applicable — no user-visible UI changes.
Checklist:
🤖 Generated with Claude Code
Summary by Gitar
assignGlossaryTermToChildrenutility function fromentity.tsas it relied on a now-deprecatedPUTwait.This will update automatically on new commits.