Refine HTTP hook redirect enforcement
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -4,7 +4,7 @@ import { log } from "../../shared"
|
||||
|
||||
const DEFAULT_HTTP_HOOK_TIMEOUT_S = 30
|
||||
const ALLOWED_SCHEMES = new Set(["http:", "https:"])
|
||||
const LOCALHOST_HOSTNAMES = new Set(["localhost", "127.0.0.1", "::1", "[::1]"])
|
||||
const LOCALHOST_HOSTNAMES = new Set(["localhost", "127.0.0.1", "[::1]"])
|
||||
|
||||
function isLocalhost(url: URL): boolean {
|
||||
return LOCALHOST_HOSTNAMES.has(url.hostname)
|
||||
@@ -64,8 +64,8 @@ export async function executeHttpHook(
|
||||
}
|
||||
|
||||
if (isPlainHttp(parsed)) {
|
||||
log("HTTP hook URL uses insecure protocol", { url: hook.url })
|
||||
if (!isLocalhost(parsed)) {
|
||||
log("HTTP hook URL uses insecure protocol", { url: hook.url })
|
||||
return {
|
||||
exitCode: 1,
|
||||
stderr: "HTTP hook URL must use HTTPS. Plain HTTP is only allowed for localhost, 127.0.0.1, and ::1.",
|
||||
@@ -81,6 +81,7 @@ export async function executeHttpHook(
|
||||
method: "POST",
|
||||
headers,
|
||||
body: stdin,
|
||||
// Reject all redirects so HTTPS hooks cannot be silently rewritten to a different origin or protocol.
|
||||
redirect: "manual",
|
||||
signal: AbortSignal.timeout(timeoutS * 1000),
|
||||
})
|
||||
@@ -104,6 +105,7 @@ export async function executeHttpHook(
|
||||
return { exitCode: parsed.exitCode, stdout: body, stderr: "" }
|
||||
}
|
||||
} catch {
|
||||
// Non-JSON bodies are allowed and returned as stdout below.
|
||||
}
|
||||
|
||||
return { exitCode: 0, stdout: body, stderr: "" }
|
||||
|
||||
Reference in New Issue
Block a user