@socketsecurity/lib 5.19.1 → 5.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +105 -74
  2. package/dist/archives.js +13 -0
  3. package/dist/cacache.js +6 -8
  4. package/dist/cache-with-ttl.d.ts +7 -0
  5. package/dist/cache-with-ttl.js +27 -8
  6. package/dist/constants/socket.js +1 -1
  7. package/dist/dlx/detect.js +25 -8
  8. package/dist/dlx/lockfile.js +4 -1
  9. package/dist/dlx/manifest.d.ts +10 -4
  10. package/dist/dlx/package.d.ts +1 -1
  11. package/dist/dlx/package.js +19 -3
  12. package/dist/external/@npmcli/package-json/lib/read-package.js +40 -32
  13. package/dist/external/@npmcli/package-json/lib/sort.js +104 -92
  14. package/dist/external/@npmcli/package-json.js +9 -3968
  15. package/dist/external/@sinclair/typebox/value.js +9007 -0
  16. package/dist/external/@sinclair/typebox.js +7891 -0
  17. package/dist/external/debug.js +162 -328
  18. package/dist/external/npm-pack.js +13935 -33342
  19. package/dist/fs.js +8 -2
  20. package/dist/globs.js +5 -1
  21. package/dist/http-request.d.ts +0 -25
  22. package/dist/http-request.js +6 -5
  23. package/dist/ipc.js +43 -10
  24. package/dist/json/edit.d.ts +1 -1
  25. package/dist/json/parse.d.ts +47 -2
  26. package/dist/json/parse.js +40 -2
  27. package/dist/json/types.d.ts +49 -0
  28. package/dist/memoization.d.ts +4 -23
  29. package/dist/memoization.js +15 -49
  30. package/dist/packages/specs.js +9 -2
  31. package/dist/paths/packages.js +6 -2
  32. package/dist/process-lock.js +1 -6
  33. package/dist/promise-queue.d.ts +9 -4
  34. package/dist/promise-queue.js +10 -8
  35. package/dist/promises.d.ts +41 -0
  36. package/dist/promises.js +19 -2
  37. package/dist/regexps.d.ts +4 -13
  38. package/dist/regexps.js +60 -3
  39. package/dist/schema/parse.d.ts +26 -0
  40. package/dist/{zod.js → schema/parse.js} +14 -6
  41. package/dist/schema/types.d.ts +121 -0
  42. package/dist/schema/validate.d.ts +35 -0
  43. package/dist/schema/validate.js +98 -0
  44. package/dist/stdio/progress.js +1 -1
  45. package/dist/suppress-warnings.js +0 -2
  46. package/dist/tables.js +2 -3
  47. package/dist/url.js +5 -1
  48. package/dist/versions.js +2 -2
  49. package/dist/words.js +4 -7
  50. package/package.json +15 -14
  51. package/dist/external/zod.js +0 -15223
  52. package/dist/validation/json-parser.d.ts +0 -58
  53. package/dist/validation/json-parser.js +0 -63
  54. package/dist/validation/types.d.ts +0 -118
  55. package/dist/zod.d.ts +0 -5
  56. /package/dist/{validation → schema}/types.js +0 -0
@@ -1,58 +0,0 @@
1
- /**
2
- * @fileoverview Safe JSON parsing with validation and security controls.
3
- * Provides protection against prototype pollution, size limits, and schema
4
- * validation.
5
- *
6
- * Key Features:
7
- * - Prototype pollution protection: Blocks `__proto__`, `constructor`, and
8
- * `prototype` keys via JSON.parse reviver at any depth.
9
- * - Size limits: Configurable maximum JSON string size (default 10MB).
10
- * - Schema validation: Optional Zod-compatible schema validation.
11
- * - Memory safety: Prevents memory exhaustion attacks.
12
- */
13
- import type { SafeJsonParseOptions, Schema } from './types';
14
- /**
15
- * Safely parse JSON with optional schema validation and security controls.
16
- * Throws errors on parse failures, validation failures, or security violations.
17
- *
18
- * This is the recommended method for parsing untrusted JSON input as it
19
- * provides multiple layers of security including prototype pollution
20
- * protection and size limits.
21
- *
22
- * @template T - The expected type of the parsed data
23
- * @param jsonString - The JSON string to parse
24
- * @param schema - Optional Zod-compatible schema for validation
25
- * @param options - Parsing options for security and behavior control
26
- * @returns The parsed and validated data
27
- *
28
- * @throws {Error} When JSON string exceeds `maxSize`.
29
- * @throws {Error} When JSON parsing fails.
30
- * @throws {Error} When prototype pollution keys are detected (unless
31
- * `allowPrototype` is `true`).
32
- * @throws {Error} When schema validation fails.
33
- *
34
- * @example
35
- * ```ts
36
- * // Basic parsing with type inference
37
- * const data = safeJsonParse<User>('{"name":"Alice","age":30}')
38
- *
39
- * // With schema validation
40
- * import { z } from 'zod'
41
- * const userSchema = z.object({
42
- * name: z.string(),
43
- * age: z.number()
44
- * })
45
- * const user = safeJsonParse('{"name":"Alice","age":30}', userSchema)
46
- *
47
- * // With size limit
48
- * const data = safeJsonParse(jsonString, undefined, {
49
- * maxSize: 1024 * 1024 // 1MB
50
- * })
51
- *
52
- * // Allow prototype keys (DANGEROUS — only for trusted sources)
53
- * const data = safeJsonParse('{"__proto__": {}}', undefined, {
54
- * allowPrototype: true
55
- * })
56
- * ```
57
- */
58
- export declare function safeJsonParse<T = unknown>(jsonString: string, schema?: Schema<T> | undefined, options?: SafeJsonParseOptions): T;
@@ -1,63 +0,0 @@
1
- "use strict";
2
- /* Socket Lib - Built with esbuild */
3
- "use strict";
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
- var json_parser_exports = {};
22
- __export(json_parser_exports, {
23
- safeJsonParse: () => safeJsonParse
24
- });
25
- module.exports = __toCommonJS(json_parser_exports);
26
- const DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
27
- function prototypePollutionReviver(key, value) {
28
- if (DANGEROUS_KEYS.has(key)) {
29
- throw new Error(
30
- "JSON contains potentially malicious prototype pollution keys"
31
- );
32
- }
33
- return value;
34
- }
35
- function safeJsonParse(jsonString, schema, options = {}) {
36
- const { allowPrototype = false, maxSize = 10 * 1024 * 1024 } = options;
37
- const byteLength = Buffer.byteLength(jsonString, "utf8");
38
- if (byteLength > maxSize) {
39
- throw new Error(
40
- `JSON string exceeds maximum size limit${maxSize !== 10 * 1024 * 1024 ? ` of ${maxSize} bytes` : ""}`
41
- );
42
- }
43
- let parsed;
44
- try {
45
- parsed = allowPrototype ? JSON.parse(jsonString) : JSON.parse(jsonString, prototypePollutionReviver);
46
- } catch (error) {
47
- throw new Error(`Failed to parse JSON: ${error}`);
48
- }
49
- if (schema) {
50
- const result = schema.safeParse(parsed);
51
- if (!result.success) {
52
- const error = result.error;
53
- const errors = error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join(", ");
54
- throw new Error(`Validation failed: ${errors}`);
55
- }
56
- return result.data;
57
- }
58
- return parsed;
59
- }
60
- // Annotate the CommonJS export names for ESM import in node:
61
- 0 && (module.exports = {
62
- safeJsonParse
63
- });
@@ -1,118 +0,0 @@
1
- /**
2
- * @fileoverview Validation type definitions.
3
- * Provides core types for schema validation and JSON parsing with security features.
4
- */
5
- /**
6
- * Result of a schema validation operation.
7
- * Contains either successful parsed data or error information.
8
- *
9
- * @template T - The expected type of the parsed data
10
- *
11
- * @example
12
- * ```ts
13
- * const result: ParseResult<User> = schema.safeParse(data)
14
- * if (result.success) {
15
- * console.log(result.data) // User object
16
- * } else {
17
- * console.error(result.error) // Error details
18
- * }
19
- * ```
20
- */
21
- export interface ParseResult<T> {
22
- /** Indicates whether parsing was successful */
23
- success: boolean;
24
- /** Parsed and validated data (only present when `success` is `true`) */
25
- data?: T | undefined;
26
- /** Error information (only present when `success` is `false`) */
27
- error?: unknown;
28
- }
29
- /**
30
- * Base schema interface compatible with Zod and similar validation libraries.
31
- * Provides both safe and throwing parsing methods.
32
- *
33
- * @template T - The expected output type after validation
34
- *
35
- * @example
36
- * ```ts
37
- * import { z } from 'zod'
38
- *
39
- * const userSchema = z.object({
40
- * name: z.string(),
41
- * age: z.number()
42
- * })
43
- *
44
- * // Schema satisfies this interface
45
- * const schema: Schema<User> = userSchema
46
- * const result = schema.safeParse({ name: 'Alice', age: 30 })
47
- * ```
48
- */
49
- export interface Schema<T = unknown> {
50
- /**
51
- * Safely parse data without throwing errors.
52
- * Returns a result object indicating success or failure.
53
- *
54
- * @param data - The data to validate
55
- * @returns Parse result with success flag and data or error
56
- */
57
- safeParse(data: unknown): ParseResult<T>;
58
- /**
59
- * Parse data and throw an error if validation fails.
60
- * Use this when you want to fail fast on invalid data.
61
- *
62
- * @param data - The data to validate
63
- * @returns The validated and parsed data
64
- * @throws {Error} When validation fails
65
- */
66
- parse(data: unknown): T;
67
- /**
68
- * Optional schema name for debugging and error messages.
69
- * Useful for identifying which schema failed in complex validation chains.
70
- */
71
- _name?: string | undefined;
72
- }
73
- /**
74
- * Options for configuring safe JSON parsing with security controls.
75
- * Distinct from `JsonParseOptions` in `@socketsecurity/lib/json/types`
76
- * which is scoped to reviver/error-handling for fs-oriented JSON reads.
77
- *
78
- * @example
79
- * ```ts
80
- * const options: SafeJsonParseOptions = {
81
- * maxSize: 1024 * 1024, // 1MB limit
82
- * allowPrototype: false // Block prototype pollution
83
- * }
84
- * ```
85
- */
86
- export interface SafeJsonParseOptions {
87
- /**
88
- * Allow dangerous prototype pollution keys (`__proto__`, `constructor`, `prototype`).
89
- * Set to `true` only if you trust the JSON source completely.
90
- *
91
- * @default false
92
- *
93
- * @example
94
- * ```ts
95
- * // Will throw error by default
96
- * safeJsonParse('{"__proto__": {"polluted": true}}')
97
- *
98
- * // Allows the parse (dangerous!)
99
- * safeJsonParse('{"__proto__": {"polluted": true}}', undefined, {
100
- * allowPrototype: true
101
- * })
102
- * ```
103
- */
104
- allowPrototype?: boolean | undefined;
105
- /**
106
- * Maximum allowed size of JSON string in bytes.
107
- * Prevents memory exhaustion from extremely large payloads.
108
- *
109
- * @default 10_485_760 (10 MB)
110
- *
111
- * @example
112
- * ```ts
113
- * // Limit to 1KB
114
- * safeJsonParse(jsonString, undefined, { maxSize: 1024 })
115
- * ```
116
- */
117
- maxSize?: number | undefined;
118
- }
package/dist/zod.d.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * @fileoverview Zod schema validation library wrapper for type-safe runtime validation.
3
- * Provides access to zod's schema builder through the z object.
4
- */
5
- export { z } from './external/zod';
File without changes