Blog | G5 Cyber Security

Intranet Cross-Domain Authentication

TL;DR

Cross-domain authentication in an intranet is tricky because browsers block direct access to cookies from different domains (even within the same organisation). The best approach depends on your setup, but using a central Identity Provider (IdP) with Single Sign-On (SSO) and techniques like CORS or a reverse proxy are common solutions. This guide covers several options.

Understanding the Problem

When applications run on different subdomains (e.g., app1.example.com and app2.example.com) or even different ports, browsers treat them as separate origins for security reasons. This means cookies set by one application aren’t automatically available to the other.

Solutions

  1. Central Identity Provider (IdP) with SSO
  • CORS (Cross-Origin Resource Sharing)
  • Reverse Proxy
  • PostMessage API
  • Document Domain (Generally Discouraged)
  • Implementation Steps (CORS Example)

    1. Configure your Authentication Server: Add the Access-Control-Allow-Origin header to all authentication responses.
    2. Client-Side Code: Make sure your client-side code handles CORS preflight requests correctly.
      
      fetch('https://auth.example.com/login', {
        method: 'POST',
        mode: 'cors',
      })
      .then(...)
      
    3. Testing: Verify that your applications can successfully authenticate and access resources across domains. Use browser developer tools to check for CORS errors.

    Security Considerations

    Exit mobile version