You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(primordials): add @socketsecurity/lib/primordials export and migrate internals
Add a new public module at `./primordials` exposing safe references to
built-in constructors, static methods, and prototype methods — captured
at module load time so prototype-pollution attacks on the caller realm
can't redirect library internals.
The surface (~100 helpers) matches the Node.js-internal primordials
convention:
- Static methods retain their name: `ObjectKeys`, `ArrayIsArray`,
`JSONParse`, `ReflectApply`.
- Prototype methods are uncurried via `uncurryThis` so callers write
`StringPrototypeSlice(str, 0, 3)` instead of `str.slice(0, 3)`.
- Constructors get a `Ctor` suffix (`MapCtor`, `SetCtor`, …) to avoid
shadowing the capital-case global.
Based on the primordials file socket-packageurl-js has shipped
privately; this makes the same surface available fleet-wide so other
security-sensitive consumers (registry manifest readers, CLI parsers,
SBOM ecosystem detectors) can stop hand-capturing and stop repeating
the tsgo-destructuring workaround.
Migrate six internal socket-lib files to the new module — strictly a
cleanup, no behavior change, -16 net lines:
- src/debug.ts, src/logger.ts, src/signal-exit.ts,
src/suppress-warnings.ts: replace local `const ReflectApply =
Reflect.apply` with `import { ReflectApply } from './primordials'`.
- src/errors.ts: switch isErrorShim to use the uncurried
`ObjectPrototypeToString(value)` directly — drops the
`ReflectApply(ObjectPrototypeToString, value, [])` plumbing.
- src/objects.ts: drop ~13 lines of ad-hoc Object.* captures in
favour of the centralized imports; `__defineGetter__` stays local
(it's deprecated-but-present, not in the primordials surface).
Add test/unit/primordials.test.mts (17 tests, 100% pass) covering
constructors, Array/Object/String/Reflect/RegExp/Symbol surfaces, the
prototype-pollution resilience scenario (`Array.prototype.map`
clobbered → captured reference still works), and the `uncurryThis`
helper for callers building their own primordials.
Bump to 5.25.0.
0 commit comments