|
| 1 | +name: bughunt vlt probe |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: ['bughunt/vlt/**'] |
| 5 | +permissions: |
| 6 | + contents: read |
| 7 | +jobs: |
| 8 | + probe: |
| 9 | + strategy: |
| 10 | + fail-fast: false |
| 11 | + matrix: |
| 12 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 13 | + vlt: ['1.0.10', '1.2.0', '1.3.3'] |
| 14 | + runs-on: ${{ matrix.os }} |
| 15 | + timeout-minutes: 45 |
| 16 | + defaults: |
| 17 | + run: |
| 18 | + shell: bash |
| 19 | + env: |
| 20 | + LANG: C |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 23 | + with: |
| 24 | + persist-credentials: false |
| 25 | + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 |
| 26 | + with: |
| 27 | + node-version: 24.21.0 |
| 28 | + - name: Build CLI |
| 29 | + run: cargo build --release -p socket-patch-cli |
| 30 | + - name: Install vlt |
| 31 | + run: | |
| 32 | + js=$(bash scripts/install-vlt.sh "${{ matrix.vlt }}" "$RUNNER_TEMP/vlt" | tail -n 1) |
| 33 | + echo "VLT_JS=$js" >> "$GITHUB_ENV" |
| 34 | + - name: Write probe |
| 35 | + run: | |
| 36 | + mkdir -p probe |
| 37 | + cat > probe/mock.mjs <<'MOCKEOF' |
| 38 | + import http from 'node:http'; |
| 39 | + import zlib from 'node:zlib'; |
| 40 | + import crypto from 'node:crypto'; |
| 41 | + import fs from 'node:fs'; |
| 42 | + const PORT = +process.env.PORT || 18555; |
| 43 | + const R = `http://127.0.0.1:${PORT}`; |
| 44 | + const NAME='left-pad', VER='1.3.0', UUID='aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa', TOKEN='bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb', ORG='test-org'; |
| 45 | + const PURL=`pkg:npm/${NAME}@${VER}`; |
| 46 | + const ALT = process.env.NO_ALT ? false : true; |
| 47 | + function hdr(name,size){const b=Buffer.alloc(512);b.write(name,0);b.write('0000644\0',100);b.write('0000000\0',108);b.write('0000000\0',116);b.write(size.toString(8).padStart(11,'0')+'\0',124);b.write('00000000000\0',136);b.write(' ',148);b.write('0',156);b.write('ustar\0',257);b.write('00',263);let c=0;for(const x of b)c+=x;b.write(c.toString(8).padStart(6,'0')+'\0 ',148);return b;} |
| 48 | + function tarFiles(files){const parts=[];for(const [n,d] of files){const buf=Buffer.from(d);parts.push(hdr(n,buf.length),buf,Buffer.alloc((512-buf.length%512)%512));}parts.push(Buffer.alloc(1024));return Buffer.concat(parts);} |
| 49 | + function tarOf(content){return tarFiles([['package/package.json',JSON.stringify({name:NAME,version:VER,main:'index.js'})+'\n'],['package/index.js',content]]);} |
| 50 | + const sri = b => 'sha512-'+crypto.createHash('sha512').update(b).digest('base64'); |
| 51 | + const git = b => crypto.createHash('sha256').update(Buffer.concat([Buffer.from(`blob ${b.length}\0`), b])).digest('hex'); |
| 52 | + const PRIST = Buffer.from("module.exports = 'pristine'\n"), PATCH = Buffer.from("module.exports = 'patched'\n"); |
| 53 | + const tgz = zlib.gzipSync(tarOf(PRIST)), br = zlib.brotliCompressSync(tarOf(PRIST)), ptgz = zlib.gzipSync(tarOf(PATCH)); |
| 54 | + function wrapTar(){return zlib.gzipSync(tarFiles([['package/package.json',JSON.stringify({name:'wrapper',version:'1.0.0',main:'index.js',dependencies:{'left-pad':'1.3.0'}})+'\n'],['package/index.js',"module.exports = require('left-pad')\n"]]));} |
| 55 | + const wtgz = wrapTar(); |
| 56 | + const artPath = `/patch/npm/${NAME}/${VER}/${TOKEN}/${UUID}/${NAME}-${VER}.tgz`; |
| 57 | + const log = []; |
| 58 | + http.createServer((req,res)=>{ |
| 59 | + let body=''; req.on('data',c=>body+=c); req.on('end',()=>{ |
| 60 | + const u = req.url.split('?')[0]; log.push(req.method+' '+u); |
| 61 | + const j = o => { res.writeHead(200,{'content-type':'application/json'}); res.end(JSON.stringify(o)); }; |
| 62 | + const b = x => { res.writeHead(200,{'content-type':'application/octet-stream'}); res.end(x); }; |
| 63 | + if (u===`/${NAME}`) { |
| 64 | + const dist = {tarball:`${R}/${NAME}/-/${NAME}-${VER}.tgz`, integrity: sri(tgz)}; |
| 65 | + if (ALT) dist.alternates=[{kind:'tar.br', tarball:`${R}/${NAME}/-/${NAME}-${VER}.tar.br`, integrity: sri(br)}]; |
| 66 | + return j({name:NAME, 'dist-tags':{latest:VER}, versions:{[VER]:{name:NAME,version:VER,main:'index.js',dist}}}); |
| 67 | + } |
| 68 | + if (u===`/${NAME}/${VER}`) { const dist = {tarball:`${R}/${NAME}/-/${NAME}-${VER}.tgz`, integrity: sri(tgz)}; return j({name:NAME,version:VER,main:'index.js',dist}); } |
| 69 | + if (u==='/wrapper/1.0.0') return j({name:'wrapper',version:'1.0.0',dist:{tarball:`${R}/wrapper/-/wrapper-1.0.0.tgz`,integrity:sri(wtgz)}}); |
| 70 | + if (u==='/wrapper') return j({name:'wrapper','dist-tags':{latest:'1.0.0'},versions:{'1.0.0':{name:'wrapper',version:'1.0.0',main:'index.js',dependencies:{'left-pad':'1.3.0'},dist:{tarball:`${R}/wrapper/-/wrapper-1.0.0.tgz`,integrity:sri(wtgz)}}}}); |
| 71 | + if (u==='/wrapper/-/wrapper-1.0.0.tgz') return b(wtgz); |
| 72 | + if (u===`/${NAME}/-/${NAME}-${VER}.tgz`) return b(tgz); |
| 73 | + if (u===`/${NAME}/-/${NAME}-${VER}.tar.br`) return b(br); |
| 74 | + if (u===artPath) return b(ptgz); |
| 75 | + if (u.startsWith(`/v0/orgs/${ORG}/patches/blob/`)) { const h=u.split('/').pop(); for (const x of [PRIST,PATCH]) if (git(x)===h) return b(x); } |
| 76 | + if (u===`/v0/orgs/${ORG}/patches/batch`) { if (!body.includes(PURL)) return j({packages:[],canAccessPaidPatches:false}); return j({packages:[{purl:PURL,patches:[{uuid:UUID,purl:PURL,tier:'free',cveIds:[],ghsaIds:[],severity:'high',title:'fx'}]}],canAccessPaidPatches:false}); } |
| 77 | + if (u.startsWith(`/v0/orgs/${ORG}/patches/by-package/`)) return j({patches:[{uuid:UUID,purl:PURL,publishedAt:'2024-01-01T00:00:00Z',description:'x',license:'MIT',tier:'free',vulnerabilities:{}}],canAccessPaidPatches:false}); |
| 78 | + if (u===`/v0/orgs/${ORG}/patches/package`) return j({results:{[UUID]:{status:'granted',url:R+artPath,purl:PURL,artifacts:[{kind:'tarball',url:R+artPath,integrity:{sha512:sri(ptgz)}}],registryOverride:null}}}); |
| 79 | + if (u===`/v0/orgs/${ORG}/patches/view/${UUID}`) return j({uuid:UUID,purl:PURL,publishedAt:'2024-01-01T00:00:00Z',files:{'package/index.js':{beforeHash:git(PRIST),afterHash:git(PATCH),blobContent:PATCH.toString('base64'),beforeBlobContent:PRIST.toString('base64')}},vulnerabilities:{'GHSA-vlth-aaaa-bbbb':{cves:['CVE-2026-4242'],summary:'s',severity:'high',description:'d'}},description:'x',license:'MIT',tier:'free'}); |
| 80 | + res.writeHead(404); res.end('nf'); |
| 81 | + }); |
| 82 | + }).listen(PORT, '127.0.0.1', ()=>console.log('listening', PORT)); |
| 83 | +
|
| 84 | + MOCKEOF |
| 85 | + cat > probe/gprobe.sh <<'PROBEEOF' |
| 86 | + #!/usr/bin/env bash |
| 87 | + # usage: gprobe.sh <socket-patch> <vlt.js> <mock.mjs> |
| 88 | + set -u |
| 89 | + SP=$1; VJS=$2; MOCK=$3 |
| 90 | + export LANG=C SOCKET_NPM_REGISTRY=http://127.0.0.1:18555 SOCKET_API_URL=http://127.0.0.1:18556 SOCKET_PATCH_SERVER_URL=http://127.0.0.1:18556 SOCKET_ORG_SLUG=test-org SOCKET_API_TOKEN=fake |
| 91 | + NO_ALT=1 PORT=18555 node "$MOCK" & M1=$!; NO_ALT=1 PORT=18556 node "$MOCK" & M2=$!; sleep 2 |
| 92 | + T=${RUNNER_TEMP:-$(mktemp -d)}; W="$T/gp$RANDOM"; mkdir -p "$W"; cd "$W"; FAIL=0 |
| 93 | + export XDG_CACHE_HOME="$W/.cache" XDG_DATA_HOME="$W/.data" XDG_CONFIG_HOME="$W/.config" LOCALAPPDATA="$W/.localappdata" HOME="$W/.home"; mkdir -p "$HOME" |
| 94 | + export NPM_CONFIG_PREFIX="$W/gprefix" NPM_CONFIG_REGISTRY=http://127.0.0.1:18555/ NPM_CONFIG_CACHE="$W/.npmcache" NPM_CONFIG_AUDIT=false NPM_CONFIG_FUND=false |
| 95 | + ok() { if [ "$2" = "$3" ]; then echo "PASS $1"; else echo "FAIL $1 (got '$2' want '$3')"; FAIL=1; fi; } |
| 96 | + obs() { echo "OBS $1: $2"; } |
| 97 | + vlt() { node "$VJS" "$@" >>"$W/vlt.log" 2>&1; } |
| 98 | + req() { (cd "$W" && node -e "try{console.log(require(require('path').resolve(process.argv[1])))}catch(e){console.log('MISSING')}" "$1"); } |
| 99 | + lp() { node -e "try{console.log(require('left-pad'))}catch(e){console.log('MISSING')}"; } |
| 100 | + same() { cmp -s "$1" "$2" && echo same || echo differ; } |
| 101 | + npm install -g left-pad@1.3.0 >"$W/npm.log" 2>&1; ok setup.npm.global $? 0 |
| 102 | + GROOT=$(npm root -g | tr -d '\r'); echo "GROOT=$GROOT" |
| 103 | + G="$GROOT/left-pad"; ok setup.global "$(req "$G")" pristine; cp "$G/index.js" "$W/g.orig" |
| 104 | + mkproj() { cd "$W"; rm -rf "$1"; mkdir -p "$1"; cd "$1"; echo '{"name":"app","version":"1.0.0","dependencies":{"left-pad":"1.3.0"}}' > package.json; echo '{"config":{"registries":{"npm":"http://127.0.0.1:18555/"}}}' > vlt.json; vlt install; } |
| 105 | + mkproj proj; cp vlt-lock.json "$W/lock.orig" |
| 106 | + # report-only scan -g |
| 107 | + "$SP" scan -g --json > "$W/s1.json" 2>"$W/s1.err"; ok scan_g.rc $? 0 |
| 108 | + ok scan_g.found "$(node -e "const d=require(process.argv[1]);console.log(d.packagesWithPatches)" "$W/s1.json")" 1 |
| 109 | + ok scan_g.proj_lock "$(same "$W/lock.orig" vlt-lock.json)" same; ok scan_g.no_socket "$([ -e .socket ] && echo yes || echo no)" no |
| 110 | + ok scan_g.global_untouched "$(req "$G")" pristine |
| 111 | + # outside any project |
| 112 | + (cd "$W" && "$SP" scan -g --json > "$W/s1o.json" 2>/dev/null); ok scan_g.outside.found "$(node -e "const d=require(process.argv[1]);console.log(d.packagesWithPatches)" "$W/s1o.json")" 1 |
| 113 | + # hosted refusal |
| 114 | + "$SP" scan -g --mode hosted --json > /dev/null 2>&1; ok scan_g_hosted.rc $? 2 |
| 115 | + "$SP" scan --global-prefix "$GROOT" --mode hosted --json > /dev/null 2>&1; ok scan_prefix_hosted.rc $? 2 |
| 116 | + SOCKET_GLOBAL=1 "$SP" scan --mode hosted --json > /dev/null 2>&1; ok scan_envglobal_hosted.rc $? 2 |
| 117 | + ok hosted_refusal.proj_lock "$(same "$W/lock.orig" vlt-lock.json)" same |
| 118 | + # agent apply/vex/rollback |
| 119 | + "$SP" scan -g --mode agent --yes --json > "$W/a.json" 2>&1; ok agent_g.rc $? 0 |
| 120 | + ok agent_g.global "$(req "$G")" patched; ok agent_g.project "$(lp)" pristine |
| 121 | + "$SP" vex -g --output "$W/vex.json" > /dev/null 2>&1; ok vex_g.rc $? 0 |
| 122 | + "$SP" rollback -g --yes --json > /dev/null 2>&1; ok rollback_g.rc $? 0 |
| 123 | + ok rollback_g.bytes "$(same "$G/index.js" "$W/g.orig")" same; ok rollback_g.project "$(lp)" pristine |
| 124 | + "$SP" get pkg:npm/left-pad@1.3.0 -g --yes --json > /dev/null 2>&1; ok get_g.rc $? 0; ok get_g.global "$(req "$G")" patched |
| 125 | + "$SP" rollback -g --yes --json > /dev/null 2>&1; ok get_g.rollback "$(same "$G/index.js" "$W/g.orig")" same |
| 126 | + SOCKET_GLOBAL=1 "$SP" scan --mode agent --yes --json > /dev/null 2>&1; ok envglobal.rc $? 0; ok envglobal.global "$(req "$G")" patched; ok envglobal.project "$(lp)" pristine |
| 127 | + SOCKET_GLOBAL=1 "$SP" rollback --yes --json > /dev/null 2>&1; ok envglobal.rollback "$(same "$G/index.js" "$W/g.orig")" same |
| 128 | + # custom prefix with space + unicode |
| 129 | + CP="$W/my prefix café/node_modules"; mkdir -p "$CP"; cp -R "$G" "$CP/" |
| 130 | + "$SP" scan --global-prefix "$CP" --mode agent --yes --json > /dev/null 2>&1; ok prefix_unicode.rc $? 0 |
| 131 | + ok prefix_unicode.copy "$(req "$CP/left-pad")" patched; ok prefix_unicode.default_global "$(req "$G")" pristine |
| 132 | + "$SP" rollback --global-prefix "$CP" --yes --json > /dev/null 2>&1; ok prefix_unicode.rollback "$(same "$CP/left-pad/index.js" "$W/g.orig")" same |
| 133 | + # local scan never touches global |
| 134 | + "$SP" scan --mode agent --yes --json > /dev/null 2>&1; ok local.project "$(lp)" patched; ok local.global "$(req "$G")" pristine |
| 135 | + "$SP" rollback --yes --json > /dev/null 2>&1; ok local.rollback "$(lp)" pristine |
| 136 | + # read-only global (non-root unix only) |
| 137 | + if [ "$(uname -s | cut -c1-5)" != MINGW ] && [ "$(id -u)" != 0 ]; then |
| 138 | + chmod -R a-w "$G"; "$SP" scan -g --mode agent --yes --json > "$W/ro.json" 2>&1; rc=$? |
| 139 | + ok readonly.nonzero "$([ $rc != 0 ] && echo yes || echo no)" yes; ok readonly.global "$(req "$G")" pristine; chmod -R u+w "$G" |
| 140 | + fi |
| 141 | + # BUG candidates: rollback -g / remove -g inside hosted / vendored vlt projects |
| 142 | + for mode in hosted vendored; do for cmd in rollback remove; do |
| 143 | + mkproj "bug-$mode-$cmd" |
| 144 | + if [ $mode = hosted ]; then "$SP" scan --yes --json >/dev/null 2>&1; else "$SP" scan --mode vendored --yes --json >/dev/null 2>&1; fi |
| 145 | + rm -rf node_modules; vlt ci; cp vlt-lock.json wired.lock; before=$(lp) |
| 146 | + if [ $cmd = rollback ]; then "$SP" rollback -g --yes --json > out.json 2>/dev/null; rc=$?; else "$SP" remove pkg:npm/left-pad@1.3.0 -g --yes --json > out.json 2>/dev/null; rc=$?; fi |
| 147 | + obs "bug.$mode.${cmd}_g" "rc=$rc project_lock=$(same wired.lock vlt-lock.json) project_left_pad=$before->$(lp) .socket/vendor=$([ -d .socket/vendor ] && echo kept || echo gone)" |
| 148 | + done; done |
| 149 | + mkproj vend-agent; "$SP" scan --mode vendored --yes --json >/dev/null 2>&1 |
| 150 | + "$SP" scan -g --mode agent --yes --json > out.json 2>/dev/null; obs "bug.vendored_project.scan_g_agent" "rc=$? global=$(req "$G") warn=$(grep -o 'vendored_ownership_retained' out.json | head -1)" |
| 151 | + "$SP" rollback -g --yes --json >/dev/null 2>&1 |
| 152 | + kill $M1 $M2 2>/dev/null |
| 153 | + exit $FAIL |
| 154 | + PROBEEOF |
| 155 | + - name: Probe |
| 156 | + run: | |
| 157 | + cli="$PWD/target/release/socket-patch" |
| 158 | + if [ "$RUNNER_OS" = Windows ]; then cli="$cli.exe"; fi |
| 159 | + echo "npm root -g: $(npm root -g)" |
| 160 | + bash probe/gprobe.sh "$cli" "$VLT_JS" "$PWD/probe/mock.mjs" |
0 commit comments