Rewrite dashboard proxy origins

This commit is contained in:
Codex
2026-04-24 16:13:33 +00:00
parent 19da9775e7
commit 8b705e546f
2 changed files with 28 additions and 1 deletions
+10 -1
View File
@@ -92,14 +92,23 @@ function buildTargetUrl(requestUrl: URL) {
function copyRequestHeaders(request: Request, target: URL) {
const headers = new Headers()
const targetOrigin = target.origin
request.headers.forEach((value, key) => {
if (!HOP_BY_HOP_HEADERS.has(key.toLowerCase()) && key.toLowerCase() !== 'host') {
const lowerKey = key.toLowerCase()
if (
!HOP_BY_HOP_HEADERS.has(lowerKey) &&
lowerKey !== 'host' &&
lowerKey !== 'origin' &&
lowerKey !== 'referer'
) {
headers.set(key, value)
}
})
headers.set('host', target.host)
headers.set('origin', targetOrigin)
headers.set('referer', `${targetOrigin}/`)
return headers
}
@@ -0,0 +1,18 @@
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import path from 'node:path'
const root = process.cwd()
const proxyPath = path.join(root, 'app/api/openshell/dashboard/proxy/shared.ts')
const serverPath = path.join(root, 'server.mjs')
const proxySource = await readFile(proxyPath, 'utf8')
const serverSource = await readFile(serverPath, 'utf8')
assert.match(proxySource, /const targetOrigin = target\.origin/, 'HTTP proxy must derive an upstream-safe target origin')
assert.match(proxySource, /lowerKey !== 'origin'/, 'HTTP proxy must not forward browser Origin to OpenClaw')
assert.match(proxySource, /headers\.set\('origin', targetOrigin\)/, 'HTTP proxy must rewrite Origin to the loopback/tunnel upstream origin')
assert.match(proxySource, /headers\.set\('referer', `\$\{targetOrigin\}\/`\)/, 'HTTP proxy must rewrite Referer to the upstream origin')
assert.match(serverSource, /headers\.push\(`Origin: \$\{upstreamOrigin\.origin\}`\)/, 'WebSocket tunnel must continue rewriting Origin for gateway upgrades')
console.log('openclaw-dashboard-origin-rewrite-check: PASS dashboard proxy origin rewrite assertions')