Skip to content

⚗️ 🐛 validate feature-operation name against schema character set#4525

Open
Valpertui wants to merge 4 commits into
mainfrom
valpertui/rum-operation-name-validation
Open

⚗️ 🐛 validate feature-operation name against schema character set#4525
Valpertui wants to merge 4 commits into
mainfrom
valpertui/rum-operation-name-validation

Conversation

@Valpertui
Copy link
Copy Markdown
Member

@Valpertui Valpertui commented Apr 23, 2026

Motivation

The authoritative _vital-common-schema.json restricts vital.name to the character set [\w.@$-]* (letters, digits, _, ., @, $, -) and the backend enforces this as a server-side regex on the facet path. The Browser SDK previously had no input validation on feature-operation vitals — blank names, whitespace-only names, and names with disallowed characters were all silently accepted and shipped to intake.

This PR brings the Browser SDK in line with the cross-SDK contract shared with iOS, Android, Roku, C++, and Electron

Changes

Adds validation in addOperationStepVital (inside the existing FEATURE_OPERATION_VITAL feature-flag gate):

  • Blank / whitespace-only namedisplay.warn ("Feature operation name cannot be empty or blank. Event will not be sent."), event dropped.
  • Name with characters outside [\w.@$-]*display.warn quoting the exact backend pattern, event still emitted. The backend is the source of truth on the policy, so a client-side drop would force customers to bump the SDK if the rule is ever relaxed.
  • Valid name → silent emit.
  • operation_key is not subject to this rule (no schema restriction).

JS \w is always ASCII so no special handling is needed — the non-ASCII test case 'ログイン' pins that ASCII-only semantics are retained.

Test instructions

yarn test:unit --spec packages/rum-core/src/domain/vital/vitalCollection.spec.ts

The new tests exercise blank-drop, disallowed-character warn+emit (including Unicode and emoji), valid silent emit, and confirm operation_key with spaces/slashes still emits silently.

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file (CHANGELOG Unreleased entry)

@Valpertui Valpertui requested a review from a team as a code owner April 23, 2026 18:07
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 23, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@cit-pr-commenter-54b7da
Copy link
Copy Markdown

cit-pr-commenter-54b7da Bot commented Apr 23, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 179.16 KiB 179.55 KiB +399 B +0.22%
Rum Profiler 6.16 KiB 6.16 KiB 0 B 0.00%
Rum Recorder 27.03 KiB 27.03 KiB 0 B 0.00%
Logs 56.65 KiB 56.65 KiB 0 B 0.00%
Rum Slim 135.00 KiB 135.39 KiB +391 B +0.28%
Worker 23.63 KiB 23.63 KiB 0 B 0.00%
🚀 CPU Performance

Pending...

🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 32.43 KiB 32.06 KiB -377 B
RUM - add action 105.60 KiB 88.03 KiB -17.57 KiB
RUM - add timing 31.89 KiB 32.66 KiB +792 B
RUM - add error 99.80 KiB 93.67 KiB -6.12 KiB
RUM - start/stop session replay recording 31.26 KiB 31.56 KiB +304 B
RUM - start view 507.19 KiB 496.47 KiB -10.72 KiB
Logs - log message 100.24 KiB 104.59 KiB +4.35 KiB

🔗 RealWorld

@datadog-official
Copy link
Copy Markdown

datadog-official Bot commented Apr 23, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 66.67%
Overall Coverage: 77.01% (-0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 05ae58d | Docs | Datadog PR Page | Give us feedback!

The backend enforces [\w.@$-]* on vital.name via the vital-common-schema
facet-path rule. The Browser SDK previously had no input validation on
feature-operation vitals.

Added validation in addOperationStepVital:
- blank / whitespace-only name → display.warn, drop event
- name with characters outside [\w.@$-]* → display.warn, emit event
  anyway (backend is source of truth on character-set policy)

operation_key is not subject to this rule.
Still gated behind the FEATURE_OPERATION_VITAL experimental flag.
@Valpertui Valpertui force-pushed the valpertui/rum-operation-name-validation branch from cc112c2 to 4ca6f8a Compare April 23, 2026 18:53
Comment thread packages/rum-core/src/domain/vital/vitalCollection.ts Outdated
Comment thread packages/rum-core/src/domain/vital/vitalCollection.spec.ts Outdated
Comment thread packages/rum-core/src/domain/vital/vitalCollection.ts
Comment thread CHANGELOG.md Outdated
Valpertui and others added 3 commits April 24, 2026 09:24
Co-authored-by: Thomas Lebeau <1926949+thomas-lebeau@users.noreply.github.com>
Co-authored-by: Thomas Lebeau <1926949+thomas-lebeau@users.noreply.github.com>
Co-authored-by: Thomas Lebeau <1926949+thomas-lebeau@users.noreply.github.com>
@Valpertui
Copy link
Copy Markdown
Member Author

I have read the CLA Document and I hereby sign the CLA

@Valpertui
Copy link
Copy Markdown
Member Author

recheck

@Valpertui Valpertui requested a review from thomas-lebeau April 24, 2026 09:43

function validateOperationName(name: string): boolean {
if (typeof name !== 'string' || name.trim().length === 0) {
display.warn('Feature operation name cannot be empty or blank. Event will not be sent.')
Copy link
Copy Markdown
Collaborator

@bcaudan bcaudan May 4, 2026

Choose a reason for hiding this comment

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

💬 suggestion: ‏Similar to what has been done on electron, we should probably display an error if we won't send the event.

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.

3 participants