Spaces:
Running
Running
refactor: clean up iframe-fix.cjs code style and remove deprecated OpenClaw scope patch from start.sh
Browse files- iframe-fix.cjs +14 -12
- start.sh +0 -35
iframe-fix.cjs
CHANGED
|
@@ -4,16 +4,14 @@
|
|
| 4 |
* Intercepts OpenClaw's HTTP server to:
|
| 5 |
* 1. Allow iframe embedding (strip X-Frame-Options, fix CSP)
|
| 6 |
*/
|
| 7 |
-
|
| 8 |
|
| 9 |
-
const http = require(
|
| 10 |
-
|
| 11 |
-
console.log('[iframe-fix] Initialized: Allowing iframe embedding for *.hf.space and huggingface.co');
|
| 12 |
|
| 13 |
const origEmit = http.Server.prototype.emit;
|
| 14 |
|
| 15 |
http.Server.prototype.emit = function (event, ...args) {
|
| 16 |
-
if (event ===
|
| 17 |
const [, res] = args;
|
| 18 |
|
| 19 |
// Only intercept on the main OpenClaw server (port 7860)
|
|
@@ -27,14 +25,18 @@ http.Server.prototype.emit = function (event, ...args) {
|
|
| 27 |
res.writeHead = function (statusCode, ...whArgs) {
|
| 28 |
if (res.getHeader) {
|
| 29 |
// Strip X-Frame-Options so it can load in a Hugging Face Space iframe
|
| 30 |
-
res.removeHeader(
|
| 31 |
-
|
| 32 |
// Update Content-Security-Policy if it contains frame-ancestors 'none'
|
| 33 |
-
const csp = res.getHeader(
|
| 34 |
-
if (csp && typeof csp ===
|
| 35 |
-
res.setHeader(
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
}
|
| 39 |
}
|
| 40 |
return origWriteHead.apply(this, [statusCode, ...whArgs]);
|
|
|
|
| 4 |
* Intercepts OpenClaw's HTTP server to:
|
| 5 |
* 1. Allow iframe embedding (strip X-Frame-Options, fix CSP)
|
| 6 |
*/
|
| 7 |
+
"use strict";
|
| 8 |
|
| 9 |
+
const http = require("http");
|
|
|
|
|
|
|
| 10 |
|
| 11 |
const origEmit = http.Server.prototype.emit;
|
| 12 |
|
| 13 |
http.Server.prototype.emit = function (event, ...args) {
|
| 14 |
+
if (event === "request") {
|
| 15 |
const [, res] = args;
|
| 16 |
|
| 17 |
// Only intercept on the main OpenClaw server (port 7860)
|
|
|
|
| 25 |
res.writeHead = function (statusCode, ...whArgs) {
|
| 26 |
if (res.getHeader) {
|
| 27 |
// Strip X-Frame-Options so it can load in a Hugging Face Space iframe
|
| 28 |
+
res.removeHeader("x-frame-options");
|
| 29 |
+
|
| 30 |
// Update Content-Security-Policy if it contains frame-ancestors 'none'
|
| 31 |
+
const csp = res.getHeader("content-security-policy");
|
| 32 |
+
if (csp && typeof csp === "string") {
|
| 33 |
+
res.setHeader(
|
| 34 |
+
"content-security-policy",
|
| 35 |
+
csp.replace(
|
| 36 |
+
/frame-ancestors\s+'none'/i,
|
| 37 |
+
"frame-ancestors 'self' https://huggingface.co https://*.hf.space",
|
| 38 |
+
),
|
| 39 |
+
);
|
| 40 |
}
|
| 41 |
}
|
| 42 |
return origWriteHead.apply(this, [statusCode, ...whArgs]);
|
start.sh
CHANGED
|
@@ -380,41 +380,6 @@ chmod 600 /home/node/.openclaw/openclaw.json
|
|
| 380 |
# This preload script keeps iframe embedding working on HF Spaces.
|
| 381 |
export NODE_OPTIONS="${NODE_OPTIONS:+$NODE_OPTIONS }--require /home/node/app/iframe-fix.cjs"
|
| 382 |
|
| 383 |
-
# ββ Patch OpenClaw scope-clearing bug for headless HF auth ββ
|
| 384 |
-
# OpenClaw can clear requested operator scopes after allowing a token-auth
|
| 385 |
-
# connection without device identity, which breaks the WhatsApp guardian's
|
| 386 |
-
# web.login.wait / channels.status calls on Spaces.
|
| 387 |
-
patch_openclaw_scope_bug() {
|
| 388 |
-
local roots=(
|
| 389 |
-
"/home/node/.openclaw/openclaw-app"
|
| 390 |
-
"/usr/local/lib/node_modules/openclaw"
|
| 391 |
-
)
|
| 392 |
-
local target=""
|
| 393 |
-
local updated=0
|
| 394 |
-
|
| 395 |
-
for root in "${roots[@]}"; do
|
| 396 |
-
[ -d "$root/dist" ] || continue
|
| 397 |
-
target=$(find "$root/dist" -maxdepth 1 -type f -name 'gateway-cli-*.js' | head -n 1)
|
| 398 |
-
[ -n "$target" ] || continue
|
| 399 |
-
|
| 400 |
-
if grep -q 'return params.decision.kind !== "allow" || !params.controlUiAuthPolicy.allowBypass' "$target"; then
|
| 401 |
-
perl -0pi -e 's@return params\.decision\.kind !== "allow" \|\| !params\.controlUiAuthPolicy\.allowBypass && !params\.preserveInsecureLocalControlUiScopes && \(params\.authMethod === "token" \|\| params\.authMethod === "password" \|\| params\.authMethod === "trusted-proxy" \|\| params\.trustedProxyAuthOk === true\);@return params.decision.kind !== "allow";@g' "$target"
|
| 402 |
-
|
| 403 |
-
if grep -q 'return params.decision.kind !== "allow";' "$target"; then
|
| 404 |
-
echo "π§ Patched OpenClaw scope-clearing bug in $(basename "$target")"
|
| 405 |
-
updated=1
|
| 406 |
-
break
|
| 407 |
-
fi
|
| 408 |
-
fi
|
| 409 |
-
done
|
| 410 |
-
|
| 411 |
-
if [ "$updated" -eq 0 ]; then
|
| 412 |
-
echo "β οΈ OpenClaw scope patch not applied (bundle format may have changed)"
|
| 413 |
-
fi
|
| 414 |
-
}
|
| 415 |
-
|
| 416 |
-
patch_openclaw_scope_bug
|
| 417 |
-
|
| 418 |
# ββ Startup Summary ββ
|
| 419 |
echo ""
|
| 420 |
echo " ββββββββββββββββββββββββββββββββββββββββββββ"
|
|
|
|
| 380 |
# This preload script keeps iframe embedding working on HF Spaces.
|
| 381 |
export NODE_OPTIONS="${NODE_OPTIONS:+$NODE_OPTIONS }--require /home/node/app/iframe-fix.cjs"
|
| 382 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
# ββ Startup Summary ββ
|
| 384 |
echo ""
|
| 385 |
echo " ββββββββββββββββββββββββββββββββββββββββββββ"
|