H3 · Request

H30006Use request IP utilities instead of raw IP headers

Request-sensitive H3 handlers should not trust client-controlled forwarding headers directly.

Why it happens

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.

Fix

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))
})

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

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