Skip to content

fix(security): メディアプロキシの SVG 配信停止と外部 fetch の SSRF 対策 - #291

Merged
sasagar merged 1 commit into
devfrom
fix/proxy-xss-ssrf
Oct 14, 2026
Merged

sasagar merged 1 commit into
devfrom
fix/proxy-xss-ssrf

Conversation

@sasagar

@sasagar sasagar commented Oct 14, 2026

Copy link
Copy Markdown
Member

変更

  • lib/safeFetch.ts(新規): isPrivateAddress / assertPublicUrl / safeFetch。http(s) のみ許可、DNS 解決後の全アドレスをプライベート/ループバック/リンクローカル等で検査、リダイレクトは手動で各ホップ再検証。開発用に ALLOW_PRIVATE_NETWORK_FETCH=true で無効化可能(本番では使わない)
  • routes/proxy.ts: image/svg+xml を許可リストから削除(キャッシュヒット時も再検査)。全レスポンスに CSP: ...; sandbox・nosniff・Content-Disposition: inline。上流のステータスや Content-Type を返さない汎用エラーに。/proxy/avatar は自己 HTTP fetch をやめて内部関数呼び出しに
  • middleware/securityHeaders.ts: ルートが CSP を設定済みなら上書きしない
  • RemoteFetchService: safeFetch 経由にし、AP オブジェクト取得では activity+json / ld+json / json 以外の Content-Type を拒否
  • 配送(inbox POST)、WebPush、絵文字インポート、instance-icon、nodeinfo、RemoteLikes も safeFetch 経由に

挙動の変化

  • リモートの SVG(一部の絵文字・インスタンスアイコン)はプロキシ経由で表示されなくなる(後続でラスタライズを検討)
  • AP オブジェクトを誤った Content-Type で返すサーバーからの取得は失敗する
  • ローカル/クラスタ内のインスタンスと連合する開発・テスト環境では ALLOW_PRIVATE_NETWORK_FETCH=true が必要

確認

  • typecheck / lint / format:check / ユニットテスト 1111 件 pass

https://claude.ai/code/session_01Y29fBeRP344FME6de48wUv

- Remove image/svg+xml from the proxy allowlist; re-validate cached
  content types; add sandboxed CSP, nosniff and Content-Disposition to
  every proxy response; stop echoing upstream status/content-type
- /proxy/avatar now calls the proxy logic directly instead of
  self-fetching via the request Host
- securityHeaders no longer overwrites a route-specific CSP
- Add lib/safeFetch (isPrivateAddress, assertPublicUrl, safeFetch) with
  DNS resolution checks and per-hop redirect re-validation;
  ALLOW_PRIVATE_NETWORK_FETCH=true escape hatch for development
- Use safeFetch for ActivityPub object fetches, inbox delivery, WebPush,
  nodeinfo, instance icons, remote emoji import and Misskey API calls
- RemoteFetchService rejects non-JSON (activity/ld/json) responses;
  WebFinger accepts jrd+json

Claude-Session: https://claude.ai/code/session_01Y29fBeRP344FME6de48wUv
@coderabbitai

coderabbitai Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 26 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: Love-Rox/rox/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eb9248d0-7ee4-4fc1-9a0e-d7123e8173fc
📥 Commits

Reviewing files that changed from the base of the PR and between 1f88657 and d5e3818.

📒 Files selected for processing: 15
  • .env.example
  • packages/backend/src/lib/instance-icon.ts
  • packages/backend/src/lib/safeFetch.ts
  • packages/backend/src/middleware/securityHeaders.ts
  • packages/backend/src/routes/emojis.ts
  • packages/backend/src/routes/proxy.ts
  • packages/backend/src/services/RemoteInstanceRefreshService.ts
  • packages/backend/src/services/RemoteInstanceService.ts
  • packages/backend/src/services/WebPushService.ts
  • packages/backend/src/services/ap/ActivityDeliveryService.ts
  • packages/backend/src/services/ap/RemoteActorService.ts
  • packages/backend/src/services/ap/RemoteFetchService.ts
  • packages/backend/src/services/ap/RemoteLikesService.ts
  • packages/backend/src/tests/unit/proxy.test.ts
  • packages/backend/src/tests/unit/safeFetch.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sasagar
sasagar merged commit 768c035 into dev Oct 14, 2026
11 checks passed
This was referenced Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant