Course contentsShow
← Security
Lesson 899 of 3,05218. Web Security - CSRF and Request ForgeryFree lesson

Authentication and Authorization for Outbound Requests

Implement separate credentials for internal services; avoid forwarding user credentials or session tokens in server-side requests.

Authentication and Authorization for Outbound Requests

What you'll learn: How to properly authenticate server-side outbound requests without exposing user credentials or session tokens.

The Core Problem

When your server makes requests to internal services or external APIs on behalf of users (common in SSRF scenarios or microservices), you face a critical decision: whose identity should the request carry?

The dangerous pattern is forwarding the user's session token or credentials. If your server becomes compromised or exploited via SSRF, attackers inherit the authenticated user's permissions to all connected services—a nightmare for privilege escalation.

The Secure Approach: Service Accounts

Think of it like a restaurant analogy: When a waiter (your server) needs to fetch ingredients from the kitchen (internal service), they don't hand over the customer's credit card. Instead, the restaurant has its own account with suppliers.

Implement separate credentials for server-to-server communication:

  • Create dedicated service accounts or API keys for your application
  • Each service has its own identity separate from end users
  • Use these credentials for all outbound requests your server makes
  • Implement authorization checks at the receiving service based on what the calling service needs, not what the user could do

Why This Matters

This separation creates an authorization boundary. Even if an attacker exploits SSRF in your application:

  • They can only access what your service account permits
  • User privileges don't automatically extend to internal systems
  • You can audit and limit service-to-service permissions independently
  • Credential compromise affects one service, not all users

Key Takeaway: Never forward user credentials or session tokens in server-side outbound requests. Use dedicated service accounts with minimal necessary permissions to create proper authorization boundaries between services.