惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
月光博客
月光博客
宝玉的分享
宝玉的分享
Recent Announcements
Recent Announcements
小众软件
小众软件
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
Vercel News
Vercel News
量子位
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
腾讯CDC
有赞技术团队
有赞技术团队

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
Harden trusted-proxy source validation [AI] (#81290) · op...
pgondhi987 · 2026-05-13 · via Recent Commits to openclaw:main

@@ -1,4 +1,6 @@

1-

import { describe, expect, it, vi } from "vitest";

1+

import os from "node:os";

2+

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

3+

import { makeNetworkInterfacesSnapshot } from "../test-helpers/network-interfaces.js";

24

import { createAuthRateLimiter, type AuthRateLimiter } from "./auth-rate-limit.js";

35

import {

46

assertGatewayAuthConfigured,

@@ -558,6 +560,26 @@ describe("gateway auth", () => {

558560

});

559561560562

describe("trusted-proxy auth", () => {

563+

function mockLocalInterfaces(nonLoopbackAddress = "10.0.0.2", family: "IPv4" | "IPv6" = "IPv4") {

564+

const spy = vi.isMockFunction(os.networkInterfaces)

565+

? vi.mocked(os.networkInterfaces)

566+

: vi.spyOn(os, "networkInterfaces");

567+

spy.mockReturnValue(

568+

makeNetworkInterfacesSnapshot({

569+

lo: [{ address: "127.0.0.1", family: "IPv4", internal: true }],

570+

eth0: [{ address: nonLoopbackAddress, family }],

571+

}),

572+

);

573+

}

574+575+

beforeEach(() => {

576+

mockLocalInterfaces();

577+

});

578+579+

afterEach(() => {

580+

vi.restoreAllMocks();

581+

});

582+561583

type GatewayConnectInput = Parameters<typeof authorizeGatewayConnect>[0];

562584

const trustedProxyConfig = {

563585

userHeader: "x-forwarded-user",

@@ -602,6 +624,57 @@ describe("trusted-proxy auth", () => {

602624

expect(res.user).toBe("nick@example.com");

603625

});

604626627+

it("rejects trusted-proxy headers from the host non-loopback interface address", async () => {

628+

mockLocalInterfaces("10.0.0.1");

629+630+

const res = await authorizeTrustedProxy({

631+

trustedProxies: ["10.0.0.1"],

632+

remoteAddress: "10.0.0.1",

633+

headers: {

634+

"x-forwarded-user": "nick@example.com",

635+

"x-forwarded-proto": "https",

636+

"x-openclaw-proxy-auth": "present",

637+

},

638+

});

639+640+

expect(res.ok).toBe(false);

641+

expect(res.reason).toBe("trusted_proxy_local_interface_source");

642+

});

643+644+

it("rejects trusted-proxy headers when local interface discovery fails", async () => {

645+

vi.mocked(os.networkInterfaces).mockImplementation(() => {

646+

throw new Error("interface discovery failed");

647+

});

648+649+

const res = await authorizeTrustedProxy({

650+

trustedProxies: ["10.0.0.1"],

651+

remoteAddress: "10.0.0.1",

652+

headers: {

653+

"x-forwarded-user": "nick@example.com",

654+

"x-forwarded-proto": "https",

655+

},

656+

});

657+658+

expect(res.ok).toBe(false);

659+

expect(res.reason).toBe("trusted_proxy_local_interface_check_failed");

660+

});

661+662+

it("rejects trusted-proxy headers from a host IPv6 interface address", async () => {

663+

mockLocalInterfaces("fd7a:115c:a1e0::1234", "IPv6");

664+665+

const res = await authorizeTrustedProxy({

666+

trustedProxies: ["fd7a:115c:a1e0::1234"],

667+

remoteAddress: "fd7a:115c:a1e0::1234",

668+

headers: {

669+

"x-forwarded-user": "nick@example.com",

670+

"x-forwarded-proto": "https",

671+

},

672+

});

673+674+

expect(res.ok).toBe(false);

675+

expect(res.reason).toBe("trusted_proxy_local_interface_source");

676+

});

677+605678

it("rejects trusted-proxy HTTP requests from origins outside the allowlist", async () => {

606679

await expect(

607680

authorizeHttpGatewayConnect({