CodeSampleX

Beispiel

secure-json-parse 4.1.0: scan

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

sha256:1e5ba76f9af1230f6cc69b08a0218345a2fe0d96acddc32972b642b27243af7f

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.scan in pkg:npm/secure-json-parse@4.1.0
Pakete
Symbole
  • secure-json-parse.scan
Umgebung
node 22.23.2
Erstellt
2026-11-21T21:41:33Z

Contract

  1. scan(obj) returns the same object reference unchanged for clean nested objects and arrays, including constructor objects without an own prototype property or with constructor set to null
  2. scan(obj) with default options throws SyntaxError('Object contains forbidden prototype property') when an own __proto__ property exists at top level or nested inside objects/arrays
  3. scan(obj) with default options throws SyntaxError('Object contains forbidden prototype property') when an own constructor object contains an own prototype property
  4. scan(obj, { protoAction: 'remove', constructorAction: 'remove' }) deletes own __proto__ and constructor.prototype keys in place across nested structures and returns the same object reference
  5. scan(obj, { protoAction: 'ignore' }) leaves own __proto__ intact, and scan(obj, { constructorAction: 'ignore' }) leaves own constructor.prototype intact
  6. scan(obj, { safe: true }) returns null instead of throwing or deleting when a non-ignored __proto__ or constructor.prototype property is found, while still allowing ignored properties

Dateien

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

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.scan 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.scan
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:0a0ae92b1d77dfede87d5e79219ef88c5f994d9b606ebe29bbb1ce4c7b558f83","constraints":{"executionContext":"node"},"contract":["scan(obj) returns the same object reference unchanged for clean nested objects and arrays, including constructor objects without an own prototype property or with constructor set to null","scan(obj) with default options throws SyntaxError('Object contains forbidden prototype property') when an own __proto__ property exists at top level or nested inside objects/arrays","scan(obj) with default options throws SyntaxError('Object contains forbidden prototype property') when an own constructor object contains an own prototype property","scan(obj, { protoAction: 'remove', constructorAction: 'remove' }) deletes own __proto__ and constructor.prototype keys in place across nested structures and returns the same object reference","scan(obj, { protoAction: 'ignore' }) leaves own __proto__ intact, and scan(obj, { constructorAction: 'ignore' }) leaves own constructor.prototype intact","scan(obj, { safe: true }) returns null instead of throwing or deleting when a non-ignored __proto__ or constructor.prototype property is found, while still allowing ignored properties"],"goal":"verify secure-json-parse.scan 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.scan"]},"contractCommand":["node","test/contract.js"],"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.scan"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-secure-json-parse-scan",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-secure-json-parse-scan",
      "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-scan",
  "version": "1.0.0",
  "private": true,
  "description": "Verify secure-json-parse.scan behavior in secure-json-parse@4.1.0",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "secure-json-parse": "4.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify secure-json-parse.scan in pkg:npm/secure-json-parse@4.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/secure-json-parse@4.1.0"
  ],
  "symbols": [
    "secure-json-parse.scan"
  ],
  "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 { scan } = require('secure-json-parse')

function scanObject (input, options) {
  return scan(input, options)
}

module.exports = {
  scanObject
}
test/contract.js
'use strict'

const assert = require('node:assert/strict')
const { scan } = require('secure-json-parse')
const { scanObject } = require('../src/index.js')

const hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key)

// 1. Clean nested objects and arrays are returned in place unchanged
{
  const clean = JSON.parse('{"a":1,"nested":{"items":[{"constructor":{"name":"ok"}},{"constructor":null}]}}')
  const result = scanObject(clean)
  assert.strictEqual(result, clean)
  assert.deepEqual(result, {
    a: 1,
    nested: {
      items: [
        { constructor: { name: 'ok' } },
        { constructor: null }
      ]
    }
  })
}

// 2. Default options throw SyntaxError on own __proto__ (top-level and nested)
{
  const withProto = JSON.parse('{"ok":true,"__proto__":{"polluted":true}}')
  assert.throws(
    () => scan(withProto),
    { name: 'SyntaxError', message: 'Object contains forbidden prototype property' }
  )

  const nestedProto = JSON.parse('{"list":[{"deep":{"__proto__":{"polluted":true}}}]}')
  assert.throws(
    () => scan(nestedProto),
    { name: 'SyntaxError', message: 'Object contains forbidden prototype property' }
  )
}

// 3. Default options throw SyntaxError on own constructor.prototype (top-level and nested)
{
  const withCtorProto = JSON.parse('{"nested":{"constructor":{"prototype":{"polluted":true}}}}')
  assert.throws(
    () => scan(withCtorProto),
    { name: 'SyntaxError', message: 'Object contains forbidden prototype property' }
  )
}

// 4. protoAction: 'remove' and constructorAction: 'remove' strip forbidden keys in place
{
  const payload = JSON.parse(
    '{"keep":1,"__proto__":{"a":1},"nested":{"ok":2,"constructor":{"prototype":{"b":2}}}}'
  )
  const result = scan(payload, { protoAction: 'remove', constructorAction: 'remove' })
  assert.strictEqual(result, payload)
  assert.strictEqual(hasOwn(result, '__proto__'), false)
  assert.strictEqual(hasOwn(result.nested, 'constructor'), false)
  assert.deepEqual(result, { keep: 1, nested: { ok: 2 } })
}

// 5. protoAction: 'ignore' and constructorAction: 'ignore' skip the respective checks
{
  const protoIgnored = JSON.parse('{"ok":1,"__proto__":{"x":1}}')
  const protoResult = scan(protoIgnored, { protoAction: 'ignore' })
  assert.strictEqual(protoResult, protoIgnored)
  assert.strictEqual(hasOwn(protoResult, '__proto__'), true)

  const ctorIgnored = JSON.parse('{"ok":1,"constructor":{"prototype":{"x":1}}}')
  const ctorResult = scan(ctorIgnored, { constructorAction: 'ignore' })
  assert.strictEqual(ctorResult, ctorIgnored)
  assert.strictEqual(hasOwn(ctorResult, 'constructor'), true)
}

// 6. safe: true returns null instead of throwing or deleting when a forbidden key is detected
{
  const withProto = JSON.parse('{"__proto__":{"x":1}}')
  assert.strictEqual(scan(withProto, { safe: true }), null)
  assert.strictEqual(scan(withProto, { protoAction: 'remove', safe: true }), null)

  const withCtor = JSON.parse('{"constructor":{"prototype":{"x":1}}}')
  assert.strictEqual(scan(withCtor, { safe: true }), null)

  // safe: true still honors ignore actions
  assert.strictEqual(scan(withProto, { protoAction: 'ignore', safe: true }), withProto)
}

console.log('secure-json-parse.scan contract passed')

Ursprungs-Seeder

anonym