AIFeed

Mistral Vibe:面向大型代码库的编码智能体

Translation(model translation, not the source's own text)

文章标题:Mistral Vibe:面向超大代码库的编码智能体

正文:

ASML(黑色)
ASML(黑色)

PR #481 已在 fix/ssrf-metadata-protection 分支上开启:3 个文件变更,104 行新增,12 行删除。

修改前


        // services/preview/src/fetcher.ts (before)
export async function fetchPreview(rawUrl: string): Promise<Preview> {
  const res = await fetch(rawUrl, { redirect: 'follow' }); // follows anywhere
  if (!res.ok) throw new UpstreamError(res.status);
  return renderPreview(res);
}
      

任何 URL 都能传入,抓取会跟随每一次重定向,而且从不检查主机名解析到了哪个 IP。

修改后


        // services/preview/src/net.ts (new)
import ipaddr from 'ipaddr.js';
import dns from 'node:dns/promises';

const BLOCKED_RANGES = [
  '0.0.0.0/8', '10.0.0.0/8', '127.0.0.0/8', '169.254.0.0/16',
  '172.16.0.0/12', '192.168.0.0/16',
  '::/128', '::1/128', 'fc00::/7', 'fe80::/10',
].map((cidr) => ipaddr.parseCIDR(cidr));

export async function assertSafeTarget(hostname: string): Promise<string> {
  const { address } = await dns.lookup(hostname);
  const parsed = ipaddr.parse(address);
  if (BLOCKED_RANGES.some((range) => parsed.match(range))) {
    throw new UnsafeTargetError(hostname, address);
  }
  return address;
}
      

        // services/preview/src/fetcher.ts (after)
import { assertSafeTarget, parseHttpUrl, fetchPinned } from './net';

const MAX_REDIRECTS = 3;

export async function fetchPreview(rawUrl: string): Promise<Preview> {
  let target = parseHttpUrl(rawUrl); // http(s) only, no embedded credentials
  for (let hop = 0; hop <= MAX_REDIRECTS; hop++) {
    const ip = await assertSafeTarget(target.hostname); // revalidated every hop
    // connects to the IP we just validated, so a rebinding DNS can't swap it
    const res = await fetchPinned(target, ip, { redirect: 'manual' });
    if (res.status < 300 || res.status >= 400) return renderPreview(res);
    target = parseHttpUrl(res.headers.get('location'), target.origin);
  }
  throw new TooManyRedirectsError();
}
      

回归测试


        // services/preview/test/fetcher.test.ts (excerpt)
it('refuses the EC2 metadata endpoint', async () => {
  await expect(fetchPreview('http://169.254.169.254/latest/meta-data/'))
    .rejects.toThrow(UnsafeTargetError);
});

it('refuses localhost and private ranges', async () => {
  await expect(fetchPreview('http://localhost:8080/debug')).rejects.toThrow(UnsafeTargetError);
  await expect(fetchPreview('http://10.0.4.12/')).rejects.toThrow(UnsafeTargetError);
});

it('follows no redirect into an internal network', async () => {
  server.enqueueRedirect('http://10.0.4.12/');
  await expect(fetchPreview('https://cdn.example/banner.png'))
    .rejects.toThrow(UnsafeTargetError);
});

it('pins the validated IP so rebinding DNS cannot redirect the connection', async () => {
  dnsMock.lookupReturnsOnce('203.0.113.7').thenReturns('10.0.9.9');
  server.enqueuePng();
  await fetchPreview('https://rebind.example/banner.png');
  expect(server.lastConnectedIp()).toBe('203.0.113.7');
});

it('still renders allowed public URLs', async () => {
  server.enqueuePng();
  const preview = await fetchPreview('https://cdn.example/banner.png');
  expect(preview.mimeType).toBe('image/png');
});
      

拉取请求

fix(preview): block SSRF to cloud metadata and internal networks


        ## Summary

The preview fetcher followed redirects without checking where they pointed,
so a user-supplied URL could reach the EC2 metadata endpoint and return the
instance role's temporary credentials. Confirmed by the red team as SEC-1042.

- Resolve each hostname and reject loopback, RFC 1918, link-local and the
  IPv6 equivalents before connecting.
- Follow redirects manually and revalidate every hop.
- Pin the connection to the validated IP so DNS rebinding cannot swap it
  between check and connect.

Fixes SEC-1042.

## Risk

验证只涉及 fetch 路径。允许的公开预览行为与之前相同。如果合法目标被拦截,它会以 UnsafeTargetError 显式失败,而不是静默改变行为。

## 测试

- services/preview/test/fetcher.test.ts 中新增 8 个回归测试
- npm test:61 项通过,类型检查无报错
- 手动验证:metadata 端点、localhost、10/8 直连、重定向到 169.254.169.254、双重解析 rebinding 尝试

## 回滚

回退并重新部署。无 schema 或配置变更。

## 范围之外

- 全舰队范围强制 IMDSv2,跟踪为 SEC-1043
- 缩小预览 IAM 角色权限范围,跟踪为 SEC-1044
      

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by Hacker News
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗