Skip to content

chore(node-client): harden existing platform implementation#1403

Merged
joker23 merged 8 commits into
mainfrom
skz/sdk-2195/node-client-sdk-next-port-client-harden-platform-io
Jun 2, 2026
Merged

chore(node-client): harden existing platform implementation#1403
joker23 merged 8 commits into
mainfrom
skz/sdk-2195/node-client-sdk-next-port-client-harden-platform-io

Conversation

@joker23

@joker23 joker23 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Hardens the Node platform layer landed in #1393, ahead of the client-side SDK implementation that builds on it. First atomic in the node-client port stack.

  • NodeStorage: log (no longer swallow) flush errors; validate/log on malformed cache reads and ignore non-string cache values; write the temp file via an exclusive wx open so the write cannot be redirected through a symlink; warn when getNodeStorage is called with a localStoragePath that differs from the process singleton's.

Note

Medium Risk
Changes on-disk cache semantics and filesystem write behavior; low blast radius but incorrect handling could affect flag persistence or local file security.

Overview
Hardens the Node client platform layer around flag disk cache and tightens related tests.

NodeStorage now treats a missing cache file as a normal first run (no warning, no empty rewrite). Malformed or unreadable cache files trigger a warn and recovery write; loaded JSON must be a plain object and only string values are kept. Persists via an exclusive wx temp open (after removing any existing temp path) so writes cannot follow a symlink planted on the temp file path. getNodeStorage records the first localStoragePath and warns if a later call passes a different path; resetNodeStorage clears that path tracking too.

Tests cover first-run behavior, malformed JSON warnings, non-string cache entries, symlink safety, singleton path mismatch warnings, and NodeInfo no longer pins the SDK version string in expectations.

Reviewed by Cursor Bugbot for commit 1962f54. Bugbot is set up for automated code reviews on this repo. Configure here.

joker23 and others added 2 commits June 1, 2026 12:43
Improves robustness of the already-merged Node platform layer:
- NodeStorage logs swallowed flush errors, validates and logs on malformed
  cache reads, writes the temp file with an exclusive (symlink-safe) open,
  and warns on localStoragePath mismatch across the process singleton.
- NodeResponse caps the buffered response body to guard against memory
  exhaustion from an oversized or hostile response.
- NodeRequests applies a default request timeout so a stuck server cannot
  hang polling or event delivery indefinitely.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Pins the new hardening behavior:
- NodeStorage: warn on malformed cache, non-string cache values ignored,
  symlink-safe temp write, localStoragePath-mismatch warning.
- NodeResponse: rejects when the body exceeds the size cap (exports
  MAX_RESPONSE_BYTES so the test references the exact threshold).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@joker23

joker23 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

@cursor review

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 26389 bytes
Compressed size limit: 29000
Uncompressed size: 129320 bytes

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 38768 bytes
Compressed size limit: 39000
Uncompressed size: 212567 bytes

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 31979 bytes
Compressed size limit: 34000
Uncompressed size: 114243 bytes

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 179654 bytes
Compressed size limit: 200000
Uncompressed size: 831422 bytes

cursor[bot]

This comment was marked as resolved.

@joker23

joker23 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

@cursor review

@joker23

joker23 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

@cursor review

cursor[bot]

This comment was marked as resolved.

cursor[bot]

This comment was marked as resolved.

@joker23 joker23 marked this pull request as ready for review June 1, 2026 17:56
@joker23 joker23 requested a review from a team as a code owner June 1, 2026 17:56

@devin-ai-integration devin-ai-integration Bot 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 6 additional findings.

Open in Devin Review

try {
await fs.writeFile(this._tempFile, content, { encoding: 'utf8', mode: 0o600 });
try {
await fs.unlink(this._tempFile);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I assume the file being missing isn't the only reason it cannot be deleted. For example if it was created by a different user or with different permissions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yea that would also cause issues, but the exception will be caught further down.

joker23 added 2 commits June 1, 2026 17:00
This is a larger problem that needs to be resolved in a separate PR
this is not standard for our sdks
@joker23 joker23 requested a review from kinyoklion June 1, 2026 21:25
Comment thread packages/sdk/node-client/src/platform/NodeStorage.ts Outdated
await handle.close();
handle = undefined;
await fs.rename(this._tempFile, this._storageFile);
} catch (error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It does feel like we probably should log something in this error handler.

joker23 and others added 2 commits June 1, 2026 18:55
Co-authored-by: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com>
@joker23 joker23 merged commit ef2fbe2 into main Jun 2, 2026
45 checks passed
@joker23 joker23 deleted the skz/sdk-2195/node-client-sdk-next-port-client-harden-platform-io branch June 2, 2026 15:01
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.

2 participants