Skip to content

Commit c4f3964

Browse files
committed
bughunt composer: home discovery probe
1 parent 045d7ec commit c4f3964

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: bughunt composer home probe
2+
on:
3+
push:
4+
branches: ['bughunt/composer/**']
5+
permissions:
6+
contents: read
7+
jobs:
8+
probe:
9+
name: ${{ matrix.os }} / composer ${{ matrix.composer }}
10+
runs-on: ${{ matrix.os }}
11+
timeout-minutes: 45
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
os: [macos-latest, windows-latest]
16+
composer: ['1.10.28', '2.2.30', '2.10.3']
17+
steps:
18+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
19+
with:
20+
persist-credentials: false
21+
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
22+
with:
23+
key: bughunt-composer-home
24+
save-if: false
25+
- uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2
26+
with:
27+
php-version: ${{ matrix.composer == '1.10.28' && '8.1' || '8.4' }}
28+
tools: composer:${{ matrix.composer }}
29+
extensions: zip, mbstring, curl, openssl
30+
coverage: none
31+
- run: cargo build --release -p socket-patch-cli
32+
- name: Probe Composer home discovery
33+
shell: bash
34+
run: |
35+
set +e
36+
T="$RUNNER_TEMP"; if command -v cygpath >/dev/null; then T="$(cygpath -m "$RUNNER_TEMP")"; fi
37+
B="$PWD/target/release/socket-patch"; [ -f "$B.exe" ] && B="$B.exe"
38+
export COMPOSER_ALLOW_SUPERUSER=1 SOCKET_TELEMETRY_DISABLED=1 COMPOSER_NO_INTERACTION=1
39+
unset COMPOSER_HOME
40+
composer --version
41+
mkdir -p "$T/pkg/src" "$T/work"
42+
printf '{"name":"acme/tool","version":"1.0.0","type":"library"}\n' > "$T/pkg/composer.json"
43+
printf '<?php\n// VULNERABLE\n' > "$T/pkg/src/Msg.php"
44+
REPO='{"type":"path","url":"'"$T/pkg"'","options":{"symlink":false}}'
45+
cat > "$T/mock.py" <<'EOF'
46+
import json,sys
47+
from http.server import BaseHTTPRequestHandler,HTTPServer
48+
class H(BaseHTTPRequestHandler):
49+
def _j(self,o):
50+
b=json.dumps(o).encode(); self.send_response(200); self.send_header('content-type','application/json'); self.send_header('content-length',str(len(b))); self.end_headers(); self.wfile.write(b)
51+
def do_POST(self):
52+
self.rfile.read(int(self.headers.get('content-length',0))); self._j({"packages":[],"canAccessPaidPatches":False})
53+
def do_GET(self): self._j({"patches":[],"canAccessPaidPatches":False})
54+
def log_message(self,*a): pass
55+
HTTPServer(('127.0.0.1',int(sys.argv[1])),H).serve_forever()
56+
EOF
57+
python3 "$T/mock.py" 18999 &
58+
sleep 3
59+
R() { echo "RESULT ${{ matrix.os }} composer-${{ matrix.composer }} $1 $2"; }
60+
NOCOMP_PATH="/usr/bin:/bin"
61+
count() { grep -o '"scannedPackages": *[0-9]*' "$1" | tr '\n' ' '; }
62+
S() { "$B" scan -g --json --api-url http://127.0.0.1:18999 --org o --api-token fake --ecosystems composer > "$1" 2>"$1.err"; echo "exit=$?" >> "$1.err"; }
63+
GH="$(composer global config home 2>/dev/null | tail -1)"; echo "composer home: $GH"
64+
[ -n "${APPDATA:-}" ] && echo "APPDATA=$APPDATA"
65+
mkdir -p "$GH"
66+
printf '{"repositories":[%s],"require":{"acme/tool":"1.0.0"}}\n' "$REPO" > "$GH/composer.json"
67+
composer global update 2>&1 | tail -2
68+
ls "$GH/vendor/acme" || true
69+
cd "$T/work"
70+
# 1. composer on PATH
71+
S on.json; echo "on PATH: $(count on.json)"; cat on.json | head -c 600; echo; tail -3 on.json.err
72+
# 2. composer not on PATH (#438 fallback)
73+
(PATH="$NOCOMP_PATH:$(dirname "$B")"; command -v composer && echo "composer still visible"; S off.json)
74+
echo "off PATH: $(count off.json)"; cat off.json | head -c 600; echo; tail -3 off.json.err
75+
# 3. macOS: XDG_CONFIG_HOME set + stale ~/.composer (#586 variant)
76+
if [ "${{ runner.os }}" = macOS ]; then
77+
export XDG_CONFIG_HOME="$T/xdg"; mkdir -p "$XDG_CONFIG_HOME"
78+
GH2="$(composer global config home 2>/dev/null | tail -1)"; echo "home with XDG_CONFIG_HOME: $GH2"
79+
mkdir -p "$GH2"
80+
printf '{"repositories":[%s],"require":{"acme/tool":"1.0.0"}}\n' "$REPO" > "$GH2/composer.json"
81+
composer global update 2>&1 | tail -1
82+
mkdir -p "$HOME/.composer"; ls -la "$HOME/.composer" | head -5
83+
S xon.json; echo "xdg on PATH: $(count xon.json)"; tail -2 xon.json.err
84+
(PATH="$NOCOMP_PATH:$(dirname "$B")"; S xoff.json); echo "xdg off PATH: $(count xoff.json)"; head -c 600 xoff.json; echo; tail -2 xoff.json.err
85+
fi
86+
exit 0

0 commit comments

Comments
 (0)