Request to ZTNA custom domain application failing with CORS error in VDI Environment
search cancel

Request to ZTNA custom domain application failing with CORS error in VDI Environment

book

Article ID: 436246

calendar_today

Updated On:

Products

Symantec ZTNA Cloud Secure Web Gateway - Cloud SWG

Issue/Introduction

Users accessing applications within a Virtual Desktop Infrastructure (VDI) environment report that certain application features are inaccessible. 

Here users is accessing locally hosted sites http://localhost:4600 in web browser which is making request to ZTNA custom domain application(e.g., https://example.com) to fetch some token or data. Request to https://example.com is failing with CORS error. The browser's developer console shows request failed with the following error message:

"Access to fetch at 'https://example.com' from origin 'http://localhost:4600' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."


Important note: In this scenario, the frontend server is http://localhost:4600 and the backend server is https://example.com. 

Environment

ZTNA Segment custom domain application access via WSS Agent or ESA agent

Cause

The issue is caused by a Cross-Origin Resource Sharing (CORS) policy violation. The browser blocks the request because the target API endpoint (e.g., https://example.com) does not explicitly permit the origin of the requesting application(e.g., http://localhost:4600). In VDI environments, this often happens when a locally hosted development or testing site attempts to fetch tokens or data from a secured API endpoint.

Resolution

To resolve this issue, the backend API server or the API Gateway (e.g., https://example.com) must be configured to include the appropriate CORS headers in its response.

Steps to Implement:

  1. Identify the Requesting Origin: Determine the exact URL of the application making the request (e.g., http://localhost:4600).

  2. Modify API Headers: Configure the backend API server or the API Gateway (e.g., https://example.com) to include the 'Access-Control-Allow-Origin' header in response.

  3. Set Header Value: Set the header value to match the requesting origin.

        Header Name: Access-Control-Allow-Origin
        Header Value: http://localhost:4600

  1. Allow Necessary Methods: Ensure the 'Access-Control-Allow-Methods' header includes the required HTTP methods (e.g., GET, POST, OPTIONS).

  2. Verify Configuration: Use the browser's Network tab to confirm that the response from 'https://example.com' now includes the 'Access-Control-Allow-Origin: http://localhost:4600' header.

 

Example Configuration

If the application is running on 'http://localhost:4600' and needs to access 'https://example.com, the server(e.g., 'https://example.com') response header should look like following:

 

HTTP/1.1 200 OK
Content-Type: application/json
Access-Control-Allow-Origin: http://localhost:4600
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization