Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/infra/test/edge-local.sh # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / infra / test / edge-local.sh` 261 lines ยท 19257 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # Local functional test of the forge nginx edge (infra/nginx/*) WITHOUT touching the hub. 3 # Runs a throwaway nginx (any host with nginx >= 1.25, python3, openssl, curl >= 8.2) on 4 # loopback ports, with the real infra snippets (paths rewritten into a temp dir), a stand-in 5 # upstream on 127.0.0.1:18480 that echoes what it received, and PROXY-protocol clients via 6 # curl --haproxy-clientip. The stand-in is a test oracle only; it is not forged. 7 # Usage: infra/test/edge-local.sh (exit 0 = every check passed) 8 # Negative controls: EDGE_MUTANT=buffering (forged responses unbuffered), =base (interplane.io 9 # X-Forge-Base not forced), =csp (forged's CSP hidden again, P2-3), =cspfallback (no edge CSP 10 # when forged sends none or a weak one), and for the www.aienos.com/forge/ redirect =method (a POST 11 # gets 301), =query (query string dropped), =headers (no security headers on the redirect) must 12 # each make the run FAIL. 13 set -u 14 HERE=$(cd "$(dirname "$0")/.." && pwd) # infra/ 15 T=$(mktemp -d "${TMPDIR:-/tmp}/forge-edge.XXXXXX") 16 P_IP=14444; P_IPPP=14448; P_AE=14446; UP=${EDGE_UP_PORT:-18480} 17 PASS=0; FAIL=0 18 ok() { PASS=$((PASS+1)); echo "PASS $*"; } 19 bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; } 20 check() { local name=$1 want=$2 got=$3; [ "$got" = "$want" ] && ok "$name ($got)" || bad "$name: want '$want' got '$got'"; } 21 has() { local name=$1 needle=$2 hay=$3; case "$hay" in *"$needle"*) ok "$name";; *) bad "$name: missing '$needle' in: $(printf %s "$hay" | head -c 300)";; esac; } 22 hasnt() { local name=$1 needle=$2 hay=$3; case "$hay" in *"$needle"*) bad "$name: unexpected '$needle'";; *) ok "$name";; esac; } 23 csps() { c -D - -o /dev/null "$1" | tr -d '\r' | sed -n 's/^[Cc]ontent-[Ss]ecurity-[Pp]olicy: //p'; } 24 # exactly one CSP header, starting with $2 25 csp1() { local name=$1 want=$2 got n; got=$(csps "$3"); n=$(printf '%s\n' "$got" | grep -c .) 26 if [ "$n" = 1 ] && case "$got" in "$want"*) true;; *) false;; esac; then ok "$name" 27 else bad "$name: want one CSP starting '$want', got $n: $(printf %s "$got" | tr '\n' '|')"; fi; } 28 EDGE_PAGE="default-src 'self'; script-src 'none'" 29 UP_PAGE="default-src 'none'; script-src 'none'; form-action 'self'" 30 31 cleanup() { [ -f "$T/nginx.pid" ] && kill "$(cat "$T/nginx.pid")" 2>/dev/null; [ -n "${UPPID:-}" ] && kill "$UPPID" 2>/dev/null; rm -rf "$T"; } 32 trap cleanup EXIT 33 34 if (exec 3<>/dev/tcp/127.0.0.1/$UP) 2>/dev/null; then echo "port $UP busy (forged running here?) - refusing to test"; exit 2; fi 35 36 mkdir -p "$T"/{conf.d,snippets,sites,certs,tmp,tmp/cache,www/ip/quick-start,www/ae} 37 for n in interplane.io www.aienos.com; do 38 openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj "/CN=$n" -addext "subjectAltName=DNS:$n" \ 39 -keyout "$T/certs/$n.key" -out "$T/certs/$n.pem" >/dev/null 2>&1 || { echo "openssl failed"; exit 2; } 40 done 41 echo STATIC-INDEX > "$T/www/ip/index.html" 42 echo STATIC-QS > "$T/www/ip/quick-start/index.html" 43 echo "User-agent: *" > "$T/www/ip/robots.txt" 44 echo AE-INDEX > "$T/www/ae/index.html"; echo AE-404 > "$T/www/ae/404.html"; echo AE-MD > "$T/www/ae/x.md" 45 46 rw() { sed -e "s#/etc/nginx/snippets/#$T/snippets/#g" -e "s#/var/cache/nginx/forge#$T/tmp/cache#g" -e "s#127\.0\.0\.1:18480#127.0.0.1:$UP#g" "$1"; } 47 for f in "$HERE"/nginx/snippets/*.conf; do rw "$f" > "$T/snippets/$(basename "$f")"; done 48 rw "$HERE/nginx/conf.d/forge.conf" > "$T/conf.d/forge.conf" 49 rw "$HERE/nginx/sites-enabled/interplane.io" | sed \ 50 -e "s#127.0.0.1:4444 ssl#127.0.0.1:$P_IP ssl#" -e "s#127.0.0.1:4448 ssl#127.0.0.1:$P_IPPP ssl#" \ 51 -e "s#/etc/nginx/certs/interplane.io/fullchain.pem#$T/certs/interplane.io.pem#" \ 52 -e "s#/etc/nginx/certs/interplane.io/key.pem#$T/certs/interplane.io.key#" \ 53 -e "s#root /var/www/interplane.io;#root $T/www/ip;#" > "$T/sites/interplane.io" 54 case "${EDGE_MUTANT:-}" in 55 buffering) sed -i.bak 's/proxy_buffering on;/proxy_buffering off;/' "$T/snippets/forge-proxy.conf" ;; 56 base) sed -i.bak '/X-Forge-Base/d' "$T/sites/interplane.io" ;; 57 csp) echo 'proxy_hide_header Content-Security-Policy;' >> "$T/snippets/forge-proxy.conf" ;; 58 cspfallback) sed -i.bak '/add_header Content-Security-Policy/d' "$T/snippets/forge-headers.conf" ;; 59 method) sed -i.bak 's/return 308 /return 301 /' "$T/snippets/aienos-forge.conf" ;; 60 query) sed -i.bak 's/\$is_args\$args//g' "$T/snippets/aienos-forge.conf" ;; 61 headers) sed -i.bak '/add_header/d' "$T/snippets/aienos-forge.conf" ;; 62 jsoncache) sed -i.bak 's/|\$forge_json//' "$T/sites/interplane.io" ;; 63 "") ;; 64 *) echo "unknown EDGE_MUTANT"; exit 2 ;; 65 esac 66 [ -n "${EDGE_MUTANT:-}" ] && echo "MUTANT ${EDGE_MUTANT} applied (this run must FAIL)" 67 grep -q "$T/www/ip" "$T/sites/interplane.io" && grep -Eq ":$P_IPPP ssl( http2)? proxy_protocol" "$T/sites/interplane.io" || { echo "rewrite of interplane.io failed"; exit 2; } 68 69 # Stand-in for the hub's www.aienos.com server: same root/404/regex shape as production. 70 cat > "$T/sites/aienos" < "$T/nginx.conf" < "$T/up.py" <<'EOF' 98 import sys, time 99 from http.server import BaseHTTPRequestHandler, HTTPServer 100 class H(BaseHTTPRequestHandler): 101 protocol_version = "HTTP/1.0" 102 def log_message(self, *a): pass 103 def echo(self, code): 104 n = int(self.headers.get("Content-Length") or 0) 105 if n: self.rfile.read(n) 106 body = "UP method=%s path=%s base=%s realip=%s xff=%s host=%s proto=%s auth=%s accept=%s\n" % ( 107 self.command, self.path, self.headers.get("X-Forge-Base"), self.headers.get("X-Real-IP"), 108 self.headers.get("X-Forwarded-For"), self.headers.get("Host"), 109 self.headers.get("X-Forwarded-Proto"), self.headers.get("Authorization"), self.headers.get("Accept")) 110 self.send_response(code) 111 self.send_header("Content-Type", "text/plain") 112 if "csp=none" in self.path: csp = None # edge must add its own 113 elif "csp=weak" in self.path: csp = "script-src *" # edge must add its own too 114 elif "/raw/" in self.path: csp = "sandbox; default-src 'none'; form-action 'none'" 115 else: csp = "default-src 'none'; script-src 'none'; form-action 'self'; frame-ancestors 'none'" 116 if csp: self.send_header("Content-Security-Policy", csp) # forged's, passed through (P2-3) 117 self.send_header("X-Powered-By", "standin") 118 if "/archive/" in self.path: # close-delimited, like forged 119 self.end_headers(); self.wfile.write(body.encode()) 120 if "big=1" in self.path: # 32 MiB: more than any socket buffer 121 pad = b"x" * 65536 122 for i in range(512): self.wfile.write(pad) 123 self.wfile.write(b"END\n"); self.wfile.flush() 124 return 125 self.send_header("Content-Length", str(len(body))); self.end_headers(); self.wfile.write(body.encode()) 126 def do_GET(self): self.echo(200) 127 def do_HEAD(self): self.echo(200) 128 def do_POST(self): self.echo(403) 129 HTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever() 130 EOF 131 if [ -n "${EDGE_SYNTAX_ONLY:-}" ]; then # e.g. the hub's own nginx binary, nothing started 132 nginx -e "$T/error.log" -t -p "$T" -c "$T/nginx.conf"; exit $? 133 fi 134 python3 "$T/up.py" $UP & UPPID=$! 135 nginx -e "$T/error.log" -t -p "$T" -c "$T/nginx.conf" 2>&1 | sed 's/^/nginx -t: /' 136 nginx -e "$T/error.log" -p "$T" -c "$T/nginx.conf" || { echo "nginx failed to start"; cat "$T/error.log"; exit 2; } 137 sleep 1 138 139 IP="https://interplane.io:$P_IPPP"; AE="https://www.aienos.com:$P_AE" 140 RES="--resolve interplane.io:$P_IPPP:127.0.0.1 --resolve interplane.io:$P_IP:127.0.0.1 --resolve www.aienos.com:$P_AE:127.0.0.1" 141 c() { curl -sk --max-time 15 $RES --haproxy-clientip 203.0.113.7 "$@"; } 142 code() { c -o /dev/null -w '%{http_code}' "$@"; } 143 144 # --- interplane.io: static first --- 145 check "ip GET / static" STATIC-INDEX "$(c "$IP/")" 146 check "ip /robots.txt static" "User-agent: *" "$(c "$IP/robots.txt")" 147 loc=$(c -o /dev/null -w '%{http_code} %{redirect_url}' "$IP/quick-start") 148 has "ip /quick-start 301" "301" "$loc" 149 h=$(c -D - -o /dev/null "$IP/quick-start") 150 has "ip redirect is relative" "location: /quick-start/" "$(printf %s "$h" | tr 'A-Z' 'a-z')" 151 hasnt "ip redirect leaks no port" ":$P_IPPP" "$h" 152 h=$(c -D - -o /dev/null "$IP/") 153 has "ip static CSP form-action self" "form-action 'self'" "$h" 154 has "ip static CSP script-src none" "script-src 'none'" "$h" 155 # --- interplane.io: everything else to forged --- 156 b=$(c -H 'X-Forge-Base: /evil/' -H 'X-Real-IP: 1.2.3.4' -H 'X-Forwarded-For: 1.2.3.4' -H 'Authorization: Basic x' "$IP/drakestapleton/cuda-crack?tab=x") 157 has "ip proxied path+query" "path=/drakestapleton/cuda-crack?tab=x" "$b" 158 has "ip X-Forge-Base forced /" "base=/ " "$b" 159 has "ip X-Real-IP from PROXY" "realip=203.0.113.7 " "$b" 160 has "ip XFF from PROXY" "xff=203.0.113.7 " "$b" 161 has "ip Authorization stripped" "auth=None" "$b" 162 has "ip Host kept" "host=interplane.io" "$b" 163 csp1 "ip forge page: forged's CSP passed through, alone" "$UP_PAGE" "$IP/drakestapleton" 164 csp1 "ip raw: forged's sandbox CSP passed through, alone" "sandbox;" "$IP/drakestapleton/cuda-crack/raw/main/rows.txt" 165 csp1 "ip page without forged CSP: edge policy" "$EDGE_PAGE" "$IP/drakestapleton?csp=none" 166 csp1 "ip raw without forged CSP: edge sandbox" "sandbox; default-src 'none'; img-src" "$IP/drakestapleton/cuda-crack/raw/main/rows.txt?csp=none" 167 h=$(csps "$IP/drakestapleton?csp=weak") 168 has "ip weak forged CSP: edge policy added" "$EDGE_PAGE" "$h" 169 has "ip weak forged CSP: forged's kept (both enforced)" "script-src *" "$h" 170 h=$(c -D - -o /dev/null "$IP/drakestapleton") 171 hasnt "ip X-Powered-By hidden" "standin" "$h" 172 has "ip forge Referrer-Policy" "same-origin" "$(printf %s "$h" | tr 'A-Z' 'a-z')" 173 check "ip PUT refused" 403 "$(code -X PUT "$IP/drakestapleton/cuda-crack")" 174 check "ip POST >64k refused" 413 "$(head -c 70000 /dev/zero | c -o /dev/null -w '%{http_code}' --data-binary @- "$IP/drakestapleton/cuda-crack/star")" 175 check "ip POST <64k reaches forged" 403 "$(code -d csrf=x "$IP/drakestapleton/cuda-crack/star")" 176 # POST without a PROXY address (legacy 4444 path) is refused; GET still works there. 177 check "ip POST w/o client addr -> 503" 503 "$(curl -sk --max-time 10 $RES -o /dev/null -w '%{http_code}' -d a=b "https://interplane.io:$P_IP/drakestapleton/cuda-crack/star")" 178 check "ip GET on legacy listener" 200 "$(curl -sk --max-time 10 $RES -o /dev/null -w '%{http_code}' "https://interplane.io:$P_IP/drakestapleton")" 179 # --- downloads: buffered (P2-1). The stand-in, like forged, serves one connection at a time. --- 180 b=$(c "$IP/drakestapleton/cuda-crack/archive/refs/heads/main.zip") 181 has "ip archive proxied" "path=/drakestapleton/cuda-crack/archive/refs/heads/main.zip" "$b" 182 has "ip archive complete" "END" "$b" 183 has "ip raw proxied" "path=/drakestapleton/cuda-crack/raw/main/README.md" "$(c "$IP/drakestapleton/cuda-crack/raw/main/README.md")" 184 c --haproxy-clientip 192.0.2.50 --limit-rate 100k --max-time 8 -o /dev/null "$IP/drakestapleton/cuda-crack/archive/refs/heads/main.zip?big=1" & SLOW=$! 185 sleep 2 186 t=$(c --haproxy-clientip 192.0.2.51 -o /dev/null -w '%{http_code} %{time_total}' "$IP/drakestapleton") 187 awk -v c="${t% *}" -v e="${t#* }" 'BEGIN{exit !(c == 200 && e < 2.0)}' && ok "ip page answers during a slow archive download ($t)" || bad "ip page stalled behind a slow download: $t" 188 c --haproxy-clientip 192.0.2.50 --limit-rate 100k --max-time 8 -o /dev/null "$IP/drakestapleton/cuda-crack/archive/refs/heads/main.zip?big=1" & SLOW2=$! 189 sleep 1 190 check "ip 3rd concurrent download from one client" 429 "$(code --haproxy-clientip 192.0.2.50 "$IP/drakestapleton/cuda-crack/archive/refs/heads/main.zip")" 191 check "ip download from another client" 200 "$(code --haproxy-clientip 192.0.2.52 "$IP/drakestapleton/cuda-crack/archive/refs/heads/main.zip")" 192 kill $SLOW $SLOW2 2>/dev/null; wait $SLOW $SLOW2 2>/dev/null 193 194 # --- www.aienos.com/forge/: a redirect to interplane.io (one-site, 2026-11-10); nothing reaches forged --- 195 check "ae GET / static untouched" AE-INDEX "$(c "$AE/")" 196 check "ae x.md static untouched" AE-MD "$(c "$AE/x.md")" 197 check "ae /nope 404 page untouched" AE-404 "$(c "$AE/nope")" 198 check "ae /forgex not redirected" AE-404 "$(c "$AE/forgex")" 199 # rd URL [curl args] -> " " 200 rd() { local u=$1; shift; c -o /dev/null -D - "$@" "$u" | tr -d '\r' | awk 'NR == 1 { s = $2 } tolower($1) == "location:" { l = $2 } END { print s, l }'; } 201 IPL=https://interplane.io 202 check "ae /forge" "301 $IPL/explore" "$(rd "$AE/forge")" 203 check "ae /forge/" "301 $IPL/explore" "$(rd "$AE/forge/")" 204 check "ae /forge?q=x keeps query" "301 $IPL/explore?q=x" "$(rd "$AE/forge?q=x")" 205 check "ae /forge/?q=x keeps query" "301 $IPL/explore?q=x" "$(rd "$AE/forge/?q=x")" 206 check "ae /forge/explore" "301 $IPL/explore" "$(rd "$AE/forge/explore")" 207 check "ae /forge/search?q=omega" "301 $IPL/search?q=omega" "$(rd "$AE/forge/search?q=omega")" 208 check "ae /forge/stars" "301 $IPL/stars" "$(rd "$AE/forge/stars")" 209 check "ae /forge/login" "301 $IPL/login" "$(rd "$AE/forge/login")" 210 check "ae profile" "301 $IPL/drakestapleton" "$(rd "$AE/forge/drakestapleton")" 211 check "ae repo" "301 $IPL/drakestapleton/CUDApp" "$(rd "$AE/forge/drakestapleton/CUDApp")" 212 check "ae releases" "301 $IPL/drakestapleton/hop/releases" "$(rd "$AE/forge/drakestapleton/hop/releases")" 213 check "ae .md path not taken by the site" "301 $IPL/drakestapleton/cuda-crack/blob/main/README.md" "$(rd "$AE/forge/drakestapleton/cuda-crack/blob/main/README.md")" 214 check "ae .om path not taken by the site" "301 $IPL/drakestapleton/omega/blob/main/x.om" "$(rd "$AE/forge/drakestapleton/omega/blob/main/x.om")" 215 check "ae archive + query" "301 $IPL/drakestapleton/cuda-crack/archive/refs/heads/main.tar.gz?x=1" "$(rd "$AE/forge/drakestapleton/cuda-crack/archive/refs/heads/main.tar.gz?x=1")" 216 check "ae rad:RID" "301 $IPL/rad:z631r2JJiVT8it4tST7RK24hpowi" "$(rd "$AE/forge/rad:z631r2JJiVT8it4tST7RK24hpowi")" 217 check "ae percent-encoding kept" "301 $IPL/drakestapleton/a%20b/blob/main/%E2%9C%93.md?q=a%26b" "$(rd "$AE/forge/drakestapleton/a%20b/blob/main/%E2%9C%93.md?q=a%26b")" 218 check "ae //forge/x -> explore" "301 $IPL/explore" "$(rd "$AE//forge/x" --path-as-is)" 219 check "ae /forge//x" "301 $IPL/x" "$(rd "$AE/forge//x" --path-as-is)" 220 check "ae encoded CRLF stays encoded" "301 $IPL/x%0d%0aSet-Cookie:%20a=b" "$(rd "$AE/forge/x%0d%0aSet-Cookie:%20a=b")" 221 hasnt "ae no injected header" "set-cookie: a=b" "$(c -D - -o /dev/null "$AE/forge/x%0d%0aSet-Cookie:%20a=b" | tr 'A-Z' 'a-z')" 222 check "ae HEAD 301" "301 $IPL/drakestapleton" "$(rd "$AE/forge/drakestapleton" -I)" 223 check "ae POST 308 keeps the method" "308 $IPL/login" "$(rd "$AE/forge/login" -d user=x)" 224 check "ae POST /forge 308" "308 $IPL/explore" "$(rd "$AE/forge" -d a=b)" 225 check "ae PUT 308" "308 $IPL/drakestapleton/cuda-crack" "$(rd "$AE/forge/drakestapleton/cuda-crack" -X PUT)" 226 for u in "$AE/forge" "$AE/forge/drakestapleton"; do 227 for m in GET POST; do 228 [ $m = POST ] && h=$(c -D - -o /dev/null -d a=b "$u") || h=$(c -D - -o /dev/null "$u") 229 l=$(printf %s "$h" | tr 'A-Z' 'a-z') 230 has "ae $m ${u#$AE} HSTS" "strict-transport-security: max-age=`31536000`; includesubdomains" "$l" 231 has "ae $m ${u#$AE} nosniff" "x-content-type-options: nosniff" "$l" 232 has "ae $m ${u#$AE} X-Frame-Options" "x-frame-options: deny" "$l" 233 has "ae $m ${u#$AE} Referrer-Policy" "referrer-policy: strict-origin-when-cross-origin" "$l" 234 has "ae $m ${u#$AE} CSP" "content-security-policy: frame-ancestors 'none'" "$l" 235 done 236 done 237 hasnt "ae redirect never proxied" "UP method=" "$(c "$AE/forge/drakestapleton/cuda-crack/archive/refs/heads/main.zip"; c -d a=b "$AE/forge/login")" 238 239 # --- POST rate limit (20r/m, burst 10): one client is cut off, another is not --- 240 codes=""; for i in $(seq 1 14); do codes="$codes $(c --haproxy-clientip 198.51.100.9 -o /dev/null -w '%{http_code}' -d a=b "$IP/drakestapleton/cuda-crack/star")"; done 241 has "POST burst hits 429" "429" "$codes" 242 check "first POST not limited" 403 "$(echo $codes | cut -d' ' -f1)" 243 check "other client not limited" 403 "$(c --haproxy-clientip 198.51.100.10 -o /dev/null -w '%{http_code}' -d a=b "$IP/drakestapleton/cuda-crack/star")" 244 codes=""; for i in $(seq 1 14); do codes="$codes $(c --haproxy-clientip 198.51.100.11 -o /dev/null -w '%{http_code}' "$IP/drakestapleton")"; done 245 hasnt "GETs never POST-limited" "429" "$codes" 246 247 # --- page cache + JSON cache key + crawler limit (L1058, L1139, L1142) --- 248 h1=$(c -D - "$IP/open/") 249 has "cache first anonymous HTML is MISS" "x-forge-cache: miss" "$(printf %s "$h1" | tr 'A-Z' 'a-z')" 250 has "cache HTML body" "accept=*/*" "$h1" 251 h2=$(c -D - "$IP/open/") 252 has "cache second anonymous HTML hit" "x-forge-cache: hit" "$(printf %s "$h2" | tr 'A-Z' 'a-z')" 253 hj=$(c -D - -H 'Accept: application/json' "$IP/open/") 254 has "cache anonymous JSON is MISS" "x-forge-cache: miss" "$(printf %s "$hj" | tr 'A-Z' 'a-z')" 255 has "cache anonymous JSON reaches forged" "accept=application/json" "$hj" 256 hc=$(c -D - -H 'Cookie: forge_session=test' "$IP/open/") 257 has "cookie bypasses page cache" "x-forge-cache: bypass" "$(printf %s "$hc" | tr 'A-Z' 'a-z')" 258 check "L1057 overlong patch segment -> 404" 404 "$(code "$IP/drakestapleton/hop/patches/$(head -c 130 /dev/zero | tr '\0' a)")" 259 260 echo "edge-local: $PASS passed, $FAIL failed" 261 [ "$FAIL" = 0 ]