Skip to content

Forward end-user IP addresses

Rate limit Supabase Auth requests by your end user's IP address, so requests from a server-side framework or proxy aren't rate limited by your server's address.

Prerequisites

To forward IP addresses, you need a secret API key. Publishable API keys and legacy anon and service_role API keys are not supported.

Turn on IP address forwarding

IP address forwarding must be explicitly enabled for new projects. Turn it on in the Dashboard or with the Management API.

In the Dashboard

In your project, open Authentication > Rate Limits and turn on Enable IP address forwarding.

With the Management API

To enable IP address forwarding from your terminal, run the following commands:

# Get your access token from https://supabase.com/dashboard/account/tokens
export SUPABASE_ACCESS_TOKEN="your-access-token"
export PROJECT_REF="your-project-ref"
# Update IP address forwarding settings
curl -X PATCH "https://api.supabase.com/v1/projects/$PROJECT_REF/config/auth" \
-H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"security_sb_forwarded_for_enabled": true
}' \
| jq '.security_sb_forwarded_for_enabled'

Set the header

Once IP address forwarding is enabled, set the Sb-Forwarded-For header to the end-user IP address. With the Supabase SDK:

import { createServerClient } from '@supabase/ssr'
const supabase = createServerClient(
'https://<your-project-id>.supabase.co',
'<your-secret-key>', // Key should start with sb_secret
{
global: {
headers: {
'sb-forwarded-for': request.headers.get('x-forwarded-for'),
},
},
}
)

Next steps

To keep going, use these pages: