Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/hooks/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ function isSdkChildContext(payload: unknown): boolean {
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";

function isSecureUrl(url: string): boolean {
try {
const parsed = new URL(url);
if (parsed.protocol === "https:") return true;
const hostname = parsed.hostname.toLowerCase();
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1") return true;
return false;
} catch {
return false;
}
}

if (SECRET && !isSecureUrl(REST_URL)) {
console.error("Error: AGENTMEMORY_SECRET is set but AGENTMEMORY_URL uses insecure http:// protocol. Use https:// or a loopback address.");
process.exit(1);
}

function authHeaders(): Record<string, string> {
const h: Record<string, string> = { "Content-Type": "application/json" };
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
Expand Down