Skip to content

fix(analytics): strip NUL bytes and slim web-analytics payload - #28232

Merged
harshach merged 5 commits into
mainfrom
harshach/strip-null-bytes-analytics
May 20, 2026
Merged

harshach merged 5 commits into
mainfrom
harshach/strip-null-bytes-analytics

Conversation

@harshach

@harshach harshach commented May 18, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Fix a PSQLException: unsupported Unicode escape sequence raised when PUT /v1/analytics/web/events/collect payloads contained the NUL character (PostgreSQL jsonb cannot store NUL bytes). WebAnalyticEventResource.sanitizeWebAnalyticEventData now strips NULs from all user-supplied string fields on both PageViewData and CustomEvent before the insert. While auditing the path I also trimmed the UI to stop sending fields that no downstream processor reads — removed the global document.body click 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), dropping hostname, language, screenSize, referrer, pageLoadTime. The Data Insights WebAnalyticsUserActivityProcessor and WebAnalyticsEntityViewProcessor only read the kept fields, so DAU/MAU and "Most Viewed Entities" reports remain unchanged.

Type of change:

  • Bug fix
  • Improvement

Tests:

Unit tests

  • Added WebAnalyticEventResourceTest (5 cases): null input, no-NUL fast path, multi-NUL stripping, end-to-end sanitization for PageViewData and CustomEvent.
  • Updated WebAnalyticsUtils.test.ts to assert the new minimum PageView payload and the userId guard; removed obsolete getReferrerPath/trackCustomEvent cases.

Backend integration tests

  • Not applicable (no new API surface; existing WebAnalyticEventResourceIT continues to exercise the endpoint).

Playwright (UI) tests

  • Not applicable (no UI surface area changed; the removed click listener and dropped payload fields are not user-visible).

Manual testing performed

  1. mvn test -pl openmetadata-service -Dtest=WebAnalyticEventResourceTest → 5/5 pass.
  2. yarn test WebAnalyticsUtils → 3/3 pass.
  3. mvn spotless:check and yarn ui-checkstyle:changed both clean.

UI screen recording / screenshots:

Not applicable — no user-visible UI changes.

Checklist:

  • I have read the CONTRIBUTING document.
  • I have added tests (unit) and listed them above.

🤖 Generated with Claude Code


Summary by Gitar

  • Test maintenance:
    • Removed the assignGlossaryTermToChildren utility function from entity.ts as it relied on a now-deprecated PUT wait.

This will update automatically on new commits.

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]>
Copilot AI review requested due to automatic review settings May 18, 2026 15:32
@harshach
harshach requested a review from a team as a code owner May 18, 2026 15:32
@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels May 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 / stripNullCharacters helpers and apply them to PageViewData and CustomEvent inside sanitizeWebAnalyticEventData.
  • Drop the track/trackCustomEvent plugin, the body click listener, and unused helpers (getReferrerPath, getPageLoadTime); reduce PageView payload to userId, sessionId, url, fullUrl.
  • Add WebAnalyticEventResourceTest and refresh WebAnalyticsUtils.test.ts to 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]>
@github-actions

github-actions Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 63%
63.36% (65487/103355) 44.15% (35936/81391) 46.91% (10563/22514)

@github-actions

github-actions Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Playwright Results — all passed (10 flaky)

✅ 4139 passed · ❌ 0 failed · 🟡 10 flaky · ⏭️ 89 skipped

Shard Passed Failed Flaky Skipped
✅ Shard 1 299 0 0 4
🟡 Shard 2 776 0 2 11
🟡 Shard 3 774 0 4 7
🟡 Shard 4 781 0 1 12
🟡 Shard 5 771 0 2 47
🟡 Shard 6 738 0 1 8
🟡 10 flaky test(s) (passed on retry)
  • Features/Glossary/GlossaryWorkflow.spec.ts › should display correct status badge color and icon (shard 2, 1 retry)
  • Features/KnowledgeCenter.spec.ts › Article mentions in description should working for Knowledge Center (shard 2, 1 retry)
  • Features/RTL.spec.ts › Verify Following widget functionality (shard 3, 1 retry)
  • Features/Table.spec.ts › Table pagination with sorting should works (shard 3, 1 retry)
  • Features/Table.spec.ts › Tags term should be consistent for search (shard 3, 1 retry)
  • Features/TestSuiteMultiPipeline.spec.ts › TestSuite multi pipeline support (shard 3, 1 retry)
  • Pages/CustomProperties.spec.ts › Should verify property name is visible for apiCollection in right panel (shard 4, 1 retry)
  • Pages/EntityDataConsumer.spec.ts › Tier Add, Update and Remove (shard 5, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard 5, 1 retry)
  • Pages/Lineage/LineageFilters.spec.ts › Verify lineage schema filter selection (shard 6, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

Copilot AI review requested due to automatic review settings May 19, 2026 18:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

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.
@gitar-bot

gitar-bot Bot commented May 20, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 2 resolved / 2 findings

Strips 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

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/analytics/WebAnalyticEventResource.java:612-614
At line 613-614, stripNullCharacters is called before containsHtml, which is correct order. However, there's a subtle issue: the containsHtml check uses Pattern.DOTALL with .*\<[^>]+>.*. If a NUL byte appeared inside an HTML tag (e.g. <scr\u0000ipt>), the stripping would reassemble a valid tag that then passes the HTML check. This is a minor concern since the stripping now happens first — the current ordering is actually correct. Disregard this.

The real issue is: stripNullCharacters(customEventData) is called only inside the CLICK branch (line 612-613). If a new CustomEventTypes value is added in the future, the else branch throws, so currently all reachable custom events are sanitized. This is fine for now but worth noting the coupling.

No actionable finding here — withdrawing.

✅ Edge Case: HTML check on eventValue may pass after NUL stripping reassembles tag

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/analytics/WebAnalyticEventResource.java:613-615
The containsHtml check (line 614) runs after stripNullCharacters (line 613). If a malicious payload contains a NUL byte splitting an HTML tag (e.g., <scr\u0000ipt>alert(1)</script>), the stripping will reassemble the tag into <script>alert(1)</script>, which containsHtml will correctly reject. So the current ordering (strip first, then validate) is actually the safe order. No issue here — the fix is correct.

Options

Display: compact → Showing less information.

Comment with these commands to change:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@harshach
harshach merged commit a2e1789 into main May 20, 2026
66 checks passed
@harshach
harshach deleted the harshach/strip-null-bytes-analytics branch May 20, 2026 15:28
harshach added a commit that referenced this pull request May 20, 2026
* 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]>
siddhant1 pushed a commit that referenced this pull request May 21, 2026
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]>
siddhant1 added a commit that referenced this pull request May 21, 2026
…#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]>
github-actions Bot pushed a commit that referenced this pull request May 21, 2026
…#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)
github-actions Bot pushed a commit that referenced this pull request May 21, 2026
…#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)

This branch was previously deployed

1 inactive deployment
test — 7f34967a Deployed May 20, 2026 by siddhant1 via playwright-ci-postgresql (2, 6) #47791
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants