H3 · H30006

Use request IP utilities instead of raw IP headers

Request-sensitive H3 handlers should not trust client-controlled forwarding headers directly.
H30006vite-doctor/h3requestwarnSuggestion

Run this rule

pnpm vite-doctor . --rules h3/request/prefer-get-request-ip

Why it matters

Reading x-forwarded-for directly trusts raw proxy input and may return a spoofed or comma-separated value instead of the client address. On H3 v2, srvx's trustProxy option decides which proxies may set the client address, and getRequestIP(event) and event.req.ip read the result.

Use getRequestIP(event) and configure trusted proxies centrally instead of reading IP headers directly.

Example

Use getRequestIP

Before

export default defineEventHandler((event) => {
  return rateLimit(event.req.headers.get('x-forwarded-for'))
})

After

// serve(app, { trustProxy: "loopback" })
export default defineEventHandler((event) => {
  return rateLimit(getRequestIP(event))
})
Copyright © 2026