CodeSampleX

Beispiel

secure-json-parse 4.1.0: default

Verifiziertes Beispiel für npm secure-json-parse 4.1.0: default. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand.

sha256:f10db203c372a151e391de1703292644b86fd86122a61ac5d8822e0aeea5ff9e

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-11-21

Fall

HOW
Ziel
verify secure-json-parse.default in pkg:npm/secure-json-parse@4.1.0
Pakete
Symbole
  • secure-json-parse.default
Umgebung
node 22.23.2
Erstellt
2026-11-21T22:35:33Z

Contract

  1. require('secure-json-parse').default is a function strictly equal to module.exports and module.exports.parse
  2. secure-json-parse.default parses valid JSON strings, Buffers, UTF-8 BOM-prefixed strings, and primitives
  3. secure-json-parse.default throws SyntaxError ('Object contains forbidden prototype property') by default on __proto__, unicode-escaped __proto__, and constructor.prototype keys, while allowing benign constructor objects without prototype
  4. secure-json-parse.default accepts an options object as 2nd argument supporting protoAction ('remove'|'ignore'), constructorAction ('remove'), and safe: true (returning null on forbidden prototype keys)
  5. secure-json-parse.default accepts a reviver function as 2nd argument together with an options object as 3rd argument
  6. secure-json-parse.default throws SyntaxError on malformed JSON even when safe: true is passed

Dateien

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.cjs

Quellartefakt herunterladen (tar.gz)

Quelltext

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify secure-json-parse.default in pkg:npm/secure-json-parse@4.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/secure-json-parse@4.1.0
Demonstrate these symbols/APIs:
  - secure-json-parse.default
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:0f306412a3edc0a277cf7fcc7eef78c0804269498139c0d646d0cf1811aeb023","constraints":{"executionContext":"node"},"contract":["require('secure-json-parse').default is a function strictly equal to module.exports and module.exports.parse","secure-json-parse.default parses valid JSON strings, Buffers, UTF-8 BOM-prefixed strings, and primitives","secure-json-parse.default throws SyntaxError ('Object contains forbidden prototype property') by default on __proto__, unicode-escaped __proto__, and constructor.prototype keys, while allowing benign constructor objects without prototype","secure-json-parse.default accepts an options object as 2nd argument supporting protoAction ('remove'|'ignore'), constructorAction ('remove'), and safe: true (returning null on forbidden prototype keys)","secure-json-parse.default accepts a reviver function as 2nd argument together with an options object as 3rd argument","secure-json-parse.default throws SyntaxError on malformed JSON even when safe: true is passed"],"goal":"verify secure-json-parse.default in pkg:npm/secure-json-parse@4.1.0","kind":"HOW","packages":["pkg:npm/secure-json-parse@4.1.0"],"schemaVersion":1,"symbols":["secure-json-parse.default"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/secure-json-parse@4.1.0"],"schemaVersion":1,"subject":"pkg:npm/secure-json-parse@4.1.0","symbols":["secure-json-parse.default"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-secure-json-parse-default",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-secure-json-parse-default",
      "version": "1.0.0",
      "dependencies": {
        "secure-json-parse": "4.1.0"
      }
    },
    "node_modules/secure-json-parse": {
      "version": "4.1.0",
      "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-4.1.0.tgz",
      "integrity": "sha512-l4KnYfEyqYJxDwlNVyRfO2E4NTHfMKAWdUuA8J0yve2Dz/E/PdBepY03RvyJpssIpRFwJoCD55wA+mEDs6ByWA==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/fastify"
        },
        {
          "type": "opencollective",
          "url": "https://opencollective.com/fastify"
        }
      ],
      "license": "BSD-3-Clause"
    }
  }
}
package.json
{
  "name": "sample-secure-json-parse-default",
  "version": "1.0.0",
  "private": true,
  "description": "Verify secure-json-parse.default in secure-json-parse@4.1.0",
  "type": "commonjs",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "secure-json-parse": "4.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify secure-json-parse.default in pkg:npm/secure-json-parse@4.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/secure-json-parse@4.1.0"
  ],
  "symbols": [
    "secure-json-parse.default"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
'use strict'

const sjson = require('secure-json-parse')

function parseWithDefault (input, reviverOrOptions, options) {
  return sjson.default(input, reviverOrOptions, options)
}

module.exports = {
  parseWithDefault,
  defaultExport: sjson.default
}
test/contract.cjs
'use strict'

const assert = require('node:assert/strict')
const sjson = require('secure-json-parse')
const { parseWithDefault, defaultExport } = require('../src/index.js')

// 1. Export identity: secure-json-parse.default is the parse function
assert.equal(typeof sjson.default, 'function')
assert.strictEqual(sjson.default, sjson)
assert.strictEqual(sjson.default, sjson.parse)
assert.strictEqual(defaultExport, sjson.default)

// 2. Parses standard JSON strings, Buffers, UTF-8 BOM input, and primitives
assert.deepEqual(sjson.default('{"a": 1, "b": "ok"}'), { a: 1, b: 'ok' })
assert.deepEqual(parseWithDefault(Buffer.from('{"buf": true}')), { buf: true })
assert.deepEqual(sjson.default('\uFEFF{"bom": 42}'), { bom: 42 })
assert.equal(sjson.default('null'), null)
assert.equal(sjson.default('123'), 123)

// 3. Default security behavior throws SyntaxError on __proto__ and constructor.prototype
assert.throws(
  () => sjson.default('{"a": 1, "__proto__": {"polluted": true}}'),
  { name: 'SyntaxError', message: 'Object contains forbidden prototype property' }
)
assert.throws(
  () => sjson.default('{"a": 1, "\\u005f_proto__": {"polluted": true}}'),
  { name: 'SyntaxError', message: 'Object contains forbidden prototype property' }
)
assert.throws(
  () => sjson.default('{"a": 1, "constructor": {"prototype": {"polluted": true}}}'),
  { name: 'SyntaxError', message: 'Object contains forbidden prototype property' }
)

// Benign constructor property without prototype key is allowed
assert.deepEqual(
  sjson.default('{"constructor": {"safe": 1}}'),
  { constructor: { safe: 1 } }
)

// 4. Options as 2nd argument: remove, ignore, and safe mode
const removedProto = sjson.default(
  '{"a": 1, "__proto__": {"polluted": true}}',
  { protoAction: 'remove' }
)
assert.deepEqual(removedProto, { a: 1 })
assert.equal(Object.prototype.hasOwnProperty.call(removedProto, '__proto__'), false)

const removedCtor = sjson.default(
  '{"a": 1, "constructor": {"prototype": {"polluted": true}}}',
  { constructorAction: 'remove' }
)
assert.deepEqual(removedCtor, { a: 1 })
assert.equal(Object.prototype.hasOwnProperty.call(removedCtor, 'constructor'), false)

const ignoredProto = sjson.default(
  '{"a": 1, "__proto__": {"polluted": true}}',
  { protoAction: 'ignore' }
)
assert.equal(Object.prototype.hasOwnProperty.call(ignoredProto, '__proto__'), true)

assert.equal(
  sjson.default('{"a": 1, "__proto__": {"polluted": true}}', { safe: true }),
  null
)

// 5. Reviver as 2nd argument combined with options as 3rd argument
const revived = parseWithDefault(
  '{"n": 2, "__proto__": {"polluted": true}}',
  (key, value) => (key === 'n' ? value * 10 : value),
  { protoAction: 'remove' }
)
assert.deepEqual(revived, { n: 20 })
assert.equal(Object.prototype.hasOwnProperty.call(revived, '__proto__'), false)

// 6. Malformed JSON throws SyntaxError even with safe: true
assert.throws(
  () => sjson.default('{invalid', { safe: true }),
  SyntaxError
)

console.log('contract passed')

Ursprungs-Seeder

anonym