Repository navigation
fix: Handle attribute names that look like attribute references - #2247
Conversation
AttributeReference skipped unescaping any component that began with `~`,
because it tested `indexOf('~')` for truthiness. References such as
`/~1a` resolved to the literal `~1a`, so private attributes named `/a`,
`/b/c` or `/~x` were never redacted from events.
Legacy users copied `privateAttributeNames` into `_meta.privateAttributes`
unchanged. The converted context sent in client flag requests then read
those literal names as references. They are now escaped as literal
references, as Go's ldcontext does.
SDK-3754
|
@launchdarkly/js-sdk-common size report |
|
@launchdarkly/js-client-sdk-common size report |
|
@launchdarkly/js-client-sdk size report |
There was a problem hiding this comment.
Risk: medium. Not approved because this exceeds the low-risk threshold: it changes private-attribute reference escaping and event redaction in shared common. SDK rules 1–3: not a release PR, allowed author, no workflow changes. Human review is needed and no reviewers were assigned.
Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver


Requirements
Related issues
SDK-3754. The failures were found by the new sdk-test-harness tests from SDK-3741.
Describe the solution you've provided
Every js-core SDK mishandled private attribute names that look like attribute references, such as
/a,/b/cand/~x.AttributeReference'sunescapecheckedref.indexOf('~')for truthiness. A component that begins with~returns index 0, so it was never unescaped./~1aresolved to a literal~1aattribute, and attributes named by escaped references in_meta.privateAttributeswere not redacted from events. The check is nowincludes('~').privateAttributeNameswere copied into_meta.privateAttributesunchanged. The context sent in client stream and poll requests then read those literal names as references. They are now escaped as literal references (/abecomes/~1a,/~xbecomes/~1~0x), as Go'sldcontextdoes withNewLiteralRef. Names that don't start with/are unchanged.redactedAttributescarries the reference string (/~1a), as go-sdk-events does.The Browser, React and Vue contract-test suppressions for the new native-EventSource
REPORTcase are in a separate PR, so thisfixdoesn't add changelog entries to those packages.Testing
The new unit tests in shared/common failed before the fix. I ran the harness branches containing the new tests (v2 and v3) with
-run 'events/.*/look like references' -run '.*/requests/.*/look like references'and each package's CI suppression file:Describe alternatives you've considered
None.
Additional context
One existing test expectation changed on purpose. A legacy private attribute name
/a/b/cnow serializes as/~1a~1b~1c.Note
Overview
Fixes mishandling of private attribute names that look like attribute references (e.g.
/a,/b/c,/~x) in shared context handling.In
AttributeReference,unescapenow usesincludes('~')instead ofindexOf('~'), so path components that start with an escape sequence (like/~1a) are unescaped correctly and resolve to literal attribute keys rather than wrong nested paths.When legacy users are converted to single-kind contexts,
privateAttributeNamesare no longer copied verbatim into_meta.privateAttributes. They are normalized throughAttributeReference(name, true).redactionName, escaping leading/names (e.g./a→/~1a) so they stay literal names and redact correctly in events and filtering without clobbering similarly named nested fields.Reviewed by Cursor Bugbot for commit 7071608. Bugbot is set up for automated code reviews on this repo. Configure here.