Spaces:
Paused
Paused
feat: enable iframe embedding by injecting a preload script to strip security headers and update CSP policies
Browse filesFiles changed (3)
- health-server.js+1-12
- iframe-fix.cjsAdded+45
- start.sh+4
5 unmodified lines678910111237 unmodified lines50515253545556575859606162636465196 unmodified lines2622632642652662672685 unmodified linesconst startTime = Date.now();const LLM_MODEL = process.env.LLM_MODEL || "Not Set";const GATEWAY_TOKEN = process.env.GATEWAY_TOKEN || "huggingclaw";const SPACE_HOST = process.env.SPACE_HOST || "localhost:7860";const TELEGRAM_ENABLED = !!process.env.TELEGRAM_BOT_TOKEN;const server = http.createServer((req, res) => {37 unmodified linesreturn;}// Auto-login redirect to OpenClaw Control UIif (req.url === "/login") {const protocol = req.headers["x-forwarded-proto"] || "http";const host = req.headers["host"] || SPACE_HOST;const target = `${protocol}://${host}/?token=${GATEWAY_TOKEN}`;res.writeHead(302, { Location: target });res.end();return;}if (req.url === "/") {res.writeHead(200, { "Content-Type": "text/html" });res.end(`196 unmodified lines<span class="stat-label">Telegram</span><span id="tg-status">Loading...</span></div><a href="/login" class="stat-btn">π Open Control UI</a></div><div class="stat-card" style="width: 100%;">5 unmodified lines6789101137 unmodified lines495051525354196 unmodified lines2512522532542552562575 unmodified linesconst startTime = Date.now();const LLM_MODEL = process.env.LLM_MODEL || "Not Set";const GATEWAY_TOKEN = process.env.GATEWAY_TOKEN || "huggingclaw";const TELEGRAM_ENABLED = !!process.env.TELEGRAM_BOT_TOKEN;const server = http.createServer((req, res) => {37 unmodified linesreturn;}if (req.url === "/") {res.writeHead(200, { "Content-Type": "text/html" });res.end(`196 unmodified lines<span class="stat-label">Telegram</span><span id="tg-status">Loading...</span></div><a href="/" class="stat-btn">π Open Control UI</a></div><div class="stat-card" style="width: 100%;">
123456789101112131415161718192021222324252627282930313233343536373839404142434445/** * iframe-fix.cjs β Node.js preload script * * Intercepts OpenClaw's HTTP server to: * 1. Allow iframe embedding (strip X-Frame-Options, fix CSP) */'use strict';
const http = require('http');
console.log('[iframe-fix] Initialized: Allowing iframe embedding for *.hf.space and huggingface.co');
const origEmit = http.Server.prototype.emit;
http.Server.prototype.emit = function (event, ...args) { if (event === 'request') { const [, res] = args;
// Only intercept on the main OpenClaw server (port 7860) const serverPort = this.address && this.address() && this.address().port; if (serverPort && serverPort !== 7860) { return origEmit.apply(this, [event, ...args]); }
// Fix iframe embedding β must be applied BEFORE any early returns const origWriteHead = res.writeHead; res.writeHead = function (statusCode, ...whArgs) { if (res.getHeader) { // Strip X-Frame-Options so it can load in a Hugging Face Space iframe res.removeHeader('x-frame-options'); // Update Content-Security-Policy if it contains frame-ancestors 'none' const csp = res.getHeader('content-security-policy'); if (csp && typeof csp === 'string') { res.setHeader('content-security-policy', csp.replace(/frame-ancestors\s+'none'/i, "frame-ancestors 'self' https://huggingface.co https://*.hf.space")); } } return origWriteHead.apply(this, [statusCode, ...whArgs]); }; }
return origEmit.apply(this, [event, ...args]);};241 unmodified lines242243244245246247241 unmodified linesecho "$CONFIG_JSON" > "/home/node/.openclaw/openclaw.json"chmod 600 /home/node/.openclaw/openclaw.json# ββ Startup Summary ββecho ""echo " ββββββββββββββββββββββββββββββββββββββββββββ"241 unmodified lines242243244245246247248249250251241 unmodified linesecho "$CONFIG_JSON" > "/home/node/.openclaw/openclaw.json"chmod 600 /home/node/.openclaw/openclaw.json# ββ Enable Iframe Fix (Security: No Token Redirect) ββ# This Node.js preload script strips X-Frame-Options to allow HF Space embeddingexport NODE_OPTIONS="${NODE_OPTIONS:+$NODE_OPTIONS }--require /home/node/app/iframe-fix.cjs"# ββ Startup Summary ββecho ""echo " ββββββββββββββββββββββββββββββββββββββββββββ"
health-server.js+1-12
iframe-fix.cjsAdded+45
start.sh+4