{visible}
"""Fictional supplier bulletin host for Aster's instructor-led webpage demo. The GET page is public. Only the teaching Space, using a shared secret, may publish a page. Content and IDs are temporary and reset when this Space sleeps. """ from __future__ import annotations import hmac import html import json import os import re import threading import time from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from urllib.parse import urlparse PAGES: dict[str, dict] = {} LOCK = threading.Lock() PAGE_ID = re.compile(r"[0-9a-f]{32}\Z") MAX_REQUEST_BYTES = 16000 MAX_BULLETIN = 2500 MAX_HIDDEN_NOTE = 6000 LIFETIME_SECONDS = 6 * 60 * 60 def render_page(bulletin: str, hidden_note: str) -> str: visible = html.escape(bulletin) hidden = html.escape(hidden_note) # The visually hidden block is still present in the HTML retrieved by an # agent. The agent's parser, not a browser screenshot, decides what it reads. return f"""
{visible}
Publish a demo page from the separate Aster Session 2 Space.
" "") return self._reply(200, landing.encode("utf-8"), "text/html; charset=utf-8") if path == "/health": return self._json(200, {"status": "running"}) match = re.fullmatch(r"/pages/([0-9a-f]{32})", path) page = get_page(match.group(1)) if match else None if page is None: return self._json(404, {"error": "page not found or expired"}) self._reply(200, page.encode("utf-8"), "text/html; charset=utf-8") def do_POST(self): if urlparse(self.path).path != "/admin/pages": return self._json(404, {"error": "unknown route"}) expected = os.getenv("PAGE_HOST_WRITE_TOKEN", "") supplied = self.headers.get("Authorization", "") if not expected or not hmac.compare_digest(supplied, f"Bearer {expected}"): return self._json(403, {"error": "publisher authorization failed"}) try: length = int(self.headers.get("Content-Length", "0")) if not 0 < length <= MAX_REQUEST_BYTES: raise ValueError("invalid request size") request = json.loads(self.rfile.read(length)) if not isinstance(request, dict): raise ValueError("body must be a JSON object") version = put_page(request) except (ValueError, UnicodeDecodeError, json.JSONDecodeError) as error: return self._json(400, {"error": str(error)}) self._json(200, {"path": f"/pages/{request['page_id']}", "version": version}) if __name__ == "__main__": print("Fictional supplier page server listening on 0.0.0.0:7860", flush=True) ThreadingHTTPServer(("0.0.0.0", 7860), Handler).serve_forever()