CodeSampleX

샘플

secure-json-parse 4.1.0: scan

검증된 샘플 — npm secure-json-parse 4.1.0: scan. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: scan(obj) returns the same object reference unchanged…

sha256:1e5ba76f9af1230f6cc69b08a0218345a2fe0d96acddc32972b642b27243af7f

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify secure-json-parse.scan in pkg:npm/secure-json-parse@4.1.0
패키지
심벌
  • secure-json-parse.scan
환경
node 22.23.2
생성일
2026-11-21T21:41:33Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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')

오리진 시더

익명