tommytracx commited on
Commit
5ccb71c
·
verified ·
1 Parent(s): 027d5cf

diag: raw proxy-header echo probe (ship-enforcer 2026-08-31)

Browse files
Files changed (3) hide show
  1. Dockerfile +5 -0
  2. README.md +6 -5
  3. app.py +63 -0
Dockerfile ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+ WORKDIR /app
3
+ COPY app.py ./
4
+ EXPOSE 7860
5
+ CMD ["python3", "-u", "app.py"]
README.md CHANGED
@@ -1,10 +1,11 @@
1
  ---
2
  title: Raw Header Echo Probe
3
- emoji:
4
- colorFrom: pink
5
- colorTo: yellow
6
  sdk: docker
 
7
  pinned: false
8
  ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Raw Header Echo Probe
3
+ emoji: 🔍
4
+ colorFrom: gray
5
+ colorTo: gray
6
  sdk: docker
7
+ app_port: 7860
8
  pinned: false
9
  ---
10
+ Diagnostic Space (temporary, ship-enforcer 2026-08-31). Echoes proxy request
11
+ bytes as JSON for mesh serving-defect root-cause analysis. Pause after use.
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Raw-socket diagnostic Space: echoes the exact bytes the HF internal proxy writes
2
+ into the container, so mesh-side header poisoning can be identified precisely.
3
+
4
+ Every request's first line + headers are base64-encoded into a JSON response.
5
+ This is deliberately temporary diagnostics tooling (ship-enforcer, 2026-08-31)
6
+ and can be paused immediately after the defect is identified.
7
+ """
8
+ import socket
9
+ import json
10
+ import base64
11
+ from http.server import BaseHTTPRequestHandler, HTTPServer
12
+
13
+ MAX = 16384
14
+
15
+
16
+ class Handler(BaseHTTPRequestHandler):
17
+ protocol_version = "HTTP/1.1"
18
+
19
+ def _echo(self):
20
+ # Read the rest of the request head (BaseHTTPRequestHandler already buffered
21
+ # the first line and headers; pull the remainder from rfile).
22
+ self.rfile.raw._sock.settimeout(2)
23
+ extra = b""
24
+ try:
25
+ while True:
26
+ chunk = self.rfile.read1(4096)
27
+ if not chunk:
28
+ break
29
+ extra += chunk
30
+ if len(extra) > MAX:
31
+ break
32
+ except Exception:
33
+ pass
34
+
35
+ first = self.request.recv(1, socket.MSG_PEEK).decode("latin1", "replace")
36
+ # Reconstruct what we know: command, path, headers as parsed.
37
+ lines = [f"{self.command} {self.path} {self.request_version}"]
38
+ for k, v in self.headers.items():
39
+ lines.append(f"{k}: {v}")
40
+ head = ("\r\n".join(lines) + "\r\n" + extra.decode("latin1", "replace")).encode("latin1", "replace")
41
+
42
+ body = json.dumps({
43
+ "first_byte_hexdump_class": "informational",
44
+ "peeked_first_char": first,
45
+ "raw_head_b64": base64.b64encode(head).decode(),
46
+ "raw_head_text": head.decode("latin1", "replace"),
47
+ "client_addr": f"{self.client_address[0]}:{self.client_address[1]}",
48
+ }).encode()
49
+
50
+ self.send_response(200)
51
+ self.send_header("Content-Type", "application/json")
52
+ self.send_header("Content-Length", str(len(body)))
53
+ self.end_headers()
54
+ self.wfile.write(body)
55
+
56
+ do_GET = do_POST = do_HEAD = _echo
57
+
58
+ def log_message(self, fmt, *args):
59
+ print("ECHOSRV:", fmt % args, self.client_address, flush=True)
60
+
61
+
62
+ if __name__ == "__main__":
63
+ HTTPServer(("0.0.0.0", 7860), Handler).serve_forever()