CodeSampleX

Sample

proxy-addr 2.0.7: all

Verified sample for npm proxy-addr 2.0.7: all. The contract ran on node 22 · linux alpine/x64 · docker and passed: proxyaddr.all(req) returns all addresses…

sha256:cf8e4187dd05a8391236cabe2ff0d8c077ae0771b3fb5418f299661a50e744c2

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 npm

Verification-run environments

Environment Contract Stages Run
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-23

Case

HOW
Goal
verify proxy-addr.all in pkg:npm/proxy-addr@2.0.7
Packages
Symbols
  • proxy-addr.all
Created
2026-08-23T04:25:34Z

Contract

  1. proxyaddr.all(req) returns all addresses from socket to client in reverse order when trust is omitted
  2. proxyaddr.all(req, trust) returns addresses up to first untrusted hop when trust predicate is provided
  3. proxyaddr.all(req, 'loopback') filters trusted loopback proxies and includes the client address
  4. proxyaddr.all(req, trustArray) supports array of CIDR subnets and built-in trust ranges
  5. proxyaddr.all(req, trustFn) passes address and hop index to custom trust predicate function
  6. proxyaddr.all(req, trust) returns single socket address when direct connection has no forwarded headers
  7. proxyaddr.all(req, trust) returns all addresses when entire proxy chain is trusted
  8. proxyaddr.all(req) supports req.connection fallback when req.socket is not present
  9. proxyaddr.all() throws TypeError when request argument is missing

Files

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

Download the source artifact (tar.gz)

Source

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 proxy-addr.all in pkg:npm/proxy-addr@2.0.7
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/proxy-addr@2.0.7
Demonstrate these symbols/APIs:
  - proxy-addr.all

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:f64055fd591c5a275ff53dd3946fa4b3e45962f6477f09897d8857fa04351b69","contract":["proxyaddr.all(req) returns all addresses from socket to client in reverse order when trust is omitted","proxyaddr.all(req, trust) returns addresses up to first untrusted hop when trust predicate is provided","proxyaddr.all(req, 'loopback') filters trusted loopback proxies and includes the client address","proxyaddr.all(req, trustArray) supports array of CIDR subnets and built-in trust ranges","proxyaddr.all(req, trustFn) passes address and hop index to custom trust predicate function","proxyaddr.all(req, trust) returns single socket address when direct connection has no forwarded headers","proxyaddr.all(req, trust) returns all addresses when entire proxy chain is trusted","proxyaddr.all(req) supports req.connection fallback when req.socket is not present","proxyaddr.all() throws TypeError when request argument is missing"],"goal":"verify proxy-addr.all in pkg:npm/proxy-addr@2.0.7","kind":"HOW","packages":["pkg:npm/proxy-addr@2.0.7"],"schemaVersion":1,"symbols":["proxy-addr.all"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/proxy-addr@2.0.7"],"schemaVersion":1,"subject":"pkg:npm/proxy-addr@2.0.7","symbols":["proxy-addr.all"],"verifierAdapter":"node-typescript@1"}
index.mjs
import proxyaddr from 'proxy-addr';

/**
 * Returns all parsed addresses from the request chain according to trust rules.
 *
 * @param {Object} req - HTTP request object.
 * @param {Function|Array|string} [trust] - Optional trust criteria (predefined range, CIDR, array, or predicate function).
 * @returns {string[]} Array of IP addresses from socket to client.
 */
export function getProxyAddressChain(req, trust) {
  return proxyaddr.all(req, trust);
}

export { proxyaddr };
export default proxyaddr;
package-lock.json
{
  "name": "sample-proxy-addr-all",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-proxy-addr-all",
      "version": "1.0.0",
      "dependencies": {
        "proxy-addr": "2.0.7"
      }
    },
    "node_modules/forwarded": {
      "version": "0.2.0",
      "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
      "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/ipaddr.js": {
      "version": "1.9.1",
      "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
      "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.10"
      }
    },
    "node_modules/proxy-addr": {
      "version": "2.0.7",
      "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
      "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
      "license": "MIT",
      "dependencies": {
        "forwarded": "0.2.0",
        "ipaddr.js": "1.9.1"
      },
      "engines": {
        "node": ">= 0.10"
      }
    }
  }
}
package.json
{
  "name": "sample-proxy-addr-all",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "proxy-addr": "2.0.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify proxy-addr.all in pkg:npm/proxy-addr@2.0.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/proxy-addr@2.0.7"
  ],
  "symbols": [
    "proxy-addr.all"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import proxyaddr from 'proxy-addr';
import { getProxyAddressChain } from '../index.mjs';

function createRequest(socketIp, forwardedFor) {
  const headers = {};
  if (forwardedFor !== undefined) {
    headers['x-forwarded-for'] = forwardedFor;
  }
  return {
    socket: { remoteAddress: socketIp },
    headers
  };
}

// 1. proxyaddr.all(req) returns all addresses from socket to client in reverse order when trust is omitted
{
  const req = createRequest('127.0.0.1', '203.0.113.195, 198.51.100.2, 10.0.0.1');
  const addrs = proxyaddr.all(req);
  assert.deepEqual(addrs, ['127.0.0.1', '10.0.0.1', '198.51.100.2', '203.0.113.195']);
  assert.deepEqual(getProxyAddressChain(req), ['127.0.0.1', '10.0.0.1', '198.51.100.2', '203.0.113.195']);
}

// 2. proxyaddr.all(req, trust) returns addresses up to first untrusted hop when trust predicate is provided
{
  const req = createRequest('127.0.0.1', '203.0.113.195, 10.0.0.1');
  const result = proxyaddr.all(req, (addr) => addr === '127.0.0.1');
  assert.deepEqual(result, ['127.0.0.1', '10.0.0.1']);
}

// 3. proxyaddr.all(req, 'loopback') filters trusted loopback proxies and includes the client address
{
  const req = createRequest('127.0.0.1', '198.51.100.5, 127.0.0.2');
  const result = proxyaddr.all(req, 'loopback');
  assert.deepEqual(result, ['127.0.0.1', '127.0.0.2', '198.51.100.5']);
}

// 4. proxyaddr.all(req, trustArray) supports array of CIDR subnets and built-in trust ranges
{
  const req = createRequest('127.0.0.1', '203.0.113.50, 192.168.1.100, 10.0.0.5');
  const result = proxyaddr.all(req, ['loopback', '10.0.0.0/8', '192.168.0.0/16']);
  assert.deepEqual(result, ['127.0.0.1', '10.0.0.5', '192.168.1.100', '203.0.113.50']);
}

// 5. proxyaddr.all(req, trustFn) passes address and hop index to custom trust predicate function
{
  const req = createRequest('127.0.0.1', '203.0.113.10, 10.0.0.1');
  const seenIndices = [];
  const seenAddresses = [];
  const result = proxyaddr.all(req, (addr, i) => {
    seenAddresses.push(addr);
    seenIndices.push(i);
    return i === 0;
  });
  assert.deepEqual(seenIndices, [0, 1]);
  assert.deepEqual(seenAddresses, ['127.0.0.1', '10.0.0.1']);
  assert.deepEqual(result, ['127.0.0.1', '10.0.0.1']);
}

// 6. proxyaddr.all(req, trust) returns single socket address when direct connection has no forwarded headers
{
  const req = createRequest('198.51.100.25');
  const result = proxyaddr.all(req, 'loopback');
  assert.deepEqual(result, ['198.51.100.25']);
}

// 7. proxyaddr.all(req, trust) returns all addresses when entire proxy chain is trusted
{
  const req = createRequest('127.0.0.1', '127.0.0.3, 127.0.0.2');
  const result = proxyaddr.all(req, 'loopback');
  assert.deepEqual(result, ['127.0.0.1', '127.0.0.2', '127.0.0.3']);
}

// 8. proxyaddr.all(req) supports req.connection fallback when req.socket is not present
{
  const req = {
    connection: { remoteAddress: '192.0.2.1' },
    headers: { 'x-forwarded-for': '198.51.100.1' }
  };
  const result = proxyaddr.all(req);
  assert.deepEqual(result, ['192.0.2.1', '198.51.100.1']);
}

// 9. proxyaddr.all() throws TypeError when request argument is missing
{
  assert.throws(() => proxyaddr.all(), /^TypeError: argument req is required$/);
  assert.throws(() => proxyaddr.all(null), /^TypeError: argument req is required$/);
}

console.log('Contract tests passed successfully.');

Origin Seeder

anonymous