Skip to content

refactor: migrate to @socketsecurity/lib/primordials#623

Merged
John-David Dalton (jdalton) merged 1 commit intomainfrom
chore/primordials
Apr 27, 2026
Merged

refactor: migrate to @socketsecurity/lib/primordials#623
John-David Dalton (jdalton) merged 1 commit intomainfrom
chore/primordials

Conversation

@jdalton
Copy link
Copy Markdown
Contributor

Summary

Swaps direct global usage for primordials across the SDK source. Primordials capture references to JavaScript built-ins (Object.keys, Array.prototype.map, JSON.parse, ...) at module load time, before user code can tamper with prototypes or globals — a hardening tool for code that processes adversarial input.

Bumps @socketsecurity/lib from 5.24.0 → 5.25.1 to pick up the @socketsecurity/lib/primordials surface (added in 5.25.0).

Audit

Used prim audit (the socket-lib/tools/prim tool):

node /path/to/socket-lib/tools/prim/bin/prim.mts audit --target . --dir src

Initial audit: 20 sites across 7 files, 11 distinct primordials, surface complete (no gaps — every primordial sdk-js needs is already in @socketsecurity/lib/primordials).

After conversion: 0 sites remain.

Sites converted

File Conversions
src/constants.ts SetSetCtor, Map<>MapCtor with type annotation
src/http-client.ts Date.now()DateNow() (9×), SetSetCtor, .trim()StringPrototypeTrim
src/quota-utils.ts ErrorErrorCtor (5×)
src/socket-sdk-class.ts ErrorErrorCtor (12×), TypeErrorTypeErrorCtor (2×), Array.isArrayArrayIsArray, .trim()StringPrototypeTrim (4×)
src/utils.ts .toLowerCase()StringPrototypeToLowerCase, SetSetCtor, .trim()StringPrototypeTrim (multi), .endsWithStringPrototypeEndsWith, Promise.withResolversPromiseWithResolvers, URLSearchParamsURLSearchParamsCtor (2×)
src/utils/header-sanitization.ts Array.isArrayArrayIsArray (2×), .toLowerCase()StringPrototypeToLowerCase

Note: prim audit reports unique-per-block sites. Manually swept all instances of each pattern within touched files for full coverage.

Verification

pnpm install         ✓
pnpm run check --all ✓ (lint + typecheck pass)
pnpm test            ✓ 565/565 tests pass

Test plan

  • Type-check passes (note: TypeScript handles aliased constructors with Ctor suffix correctly when type-annotated; MapCtor cast inline where generic type args are needed)
  • All unit tests pass (565/565)
  • CI matrix passes

Swaps direct global usage for primordials across the SDK source.
Primordials capture references to JavaScript built-ins (Object.keys,
Array.prototype.map, JSON.parse, ...) at module load time, before
user code can tamper with prototypes or globals — a hardening tool
for code that processes adversarial input.

Bumps @socketsecurity/lib 5.24.0 → 5.25.1 to pick up the
@socketsecurity/lib/primordials surface (added in 5.25.0).

Sites converted (audit found none remaining):

  src/constants.ts
    new Set(...)   → new SetCtor(...)
    new Map<...>(...) → new MapCtor(...) with type annotation

  src/http-client.ts
    Date.now()     → DateNow()  (9 sites)
    new Set(...)   → new SetCtor(...)
    str.trim()     → StringPrototypeTrim(str)

  src/quota-utils.ts
    new Error(...) → new ErrorCtor(...)  (5 sites)

  src/socket-sdk-class.ts
    new Error(...)     → new ErrorCtor(...)  (12 sites)
    new TypeError(...) → new TypeErrorCtor(...)  (2 sites)
    Array.isArray(x)   → ArrayIsArray(x)
    str.trim()         → StringPrototypeTrim(str)  (4 sites)

  src/utils.ts
    s.toLowerCase()         → StringPrototypeToLowerCase(s)
    new Set(...)            → new SetCtor(...)
    str.trim()              → StringPrototypeTrim(str)  (multiple)
    str.endsWith(...)       → StringPrototypeEndsWith(str, ...)
    Promise.withResolvers   → PromiseWithResolvers (with cast for generics)
    new URLSearchParams(...) → new URLSearchParamsCtor(...)  (2 sites)

  src/utils/header-sanitization.ts
    Array.isArray(x) → ArrayIsArray(x)  (2 sites)
    key.toLowerCase() → StringPrototypeToLowerCase(key)

prim audit: surface complete (no gaps), 0 sites remain.
prim audit run: \`node /path/to/socket-lib/tools/prim/bin/prim.mts audit --target . --dir src\`

Verification:
  pnpm install           ✓
  pnpm run check --all   ✓ (lint + typecheck pass)
  pnpm test              ✓ 565/565 tests pass
@socket-security
Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​socketsecurity/​lib@​5.24.0 ⏵ 5.25.1100100100100100

View full report

@jdalton
Copy link
Copy Markdown
Contributor Author

bugbot run

@jdalton John-David Dalton (jdalton) merged commit e4f8c48 into main Apr 27, 2026
11 checks passed
@jdalton John-David Dalton (jdalton) deleted the chore/primordials branch April 27, 2026 18:55
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