Share via

CORS Allowed Origin Not Working in Azure API Management

J, Munna Lal 0 Reputation points
2024-12-13T14:04:48.5833333+00:00

We are using Azure API Management service with an Azure Function app bound to our Azure subscription.

In our scenario, we need to allow only selected URLs through the CORS inbound policy.

Although we have configured the selected URLs to be allowed in the CORS inbound policy, our Azure Function is still accessible from other domains along with the allowed origins.

Our assumption is that except for the allowed origins, other domains should not be able to access the API Management service.

Could there be suggestions for whitelisting the URLs and properly setting up CORS?

Azure API Management
Azure API Management

An Azure service that provides a hybrid, multi-cloud management platform for APIs.

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.


2 answers

Sort by: Most helpful
  1. Anonymous
    2025-01-24T01:47:33.8766667+00:00

    Hi @J, Munna Lal,

    We sincerely apologize for the delay in response and appreciate your patience.

    It looks like you're facing an issue with the CORS inbound policy in API Management, where requests from other URLs are still being accepted despite your configuration to allow only specific domains. Here’s a straightforward approach to help you resolve this:

    • First, double-check your CORS settings in API Management. Make sure the policy is applied at the correct level—either at the API level or the operation level.
    • Ensure that your CORS policy is set up correctly. Here’s an example of how to configure it in Azure API Management: <inbound>
      <cors>
      
          <allowed-origins>
      
              <origin>https://companyabcproducts.atlassian.net</origin>
      
          </allowed-origins>
      
          <allowed-methods>
      
              <method>GET</method>
      
              <method>POST</method>
      
              <method>OPTIONS</method>
      
          </allowed-methods>
      
          <allowed-headers>
      
              <header>*</header>
      
          </allowed-headers>
      
      </cors>
      
      </inbound>
    • Sometimes, browser caching can interfere with CORS behavior. Try clearing your browser cache or testing in an incognito window to ensure that the latest CORS settings are being applied.
    • Review any other policies that might be affecting request handling, such as authentication or IP filtering. Make sure there are no conflicting policies that could allow unwanted requests.
    • Use tools like Postman or your browser's developer tools to test CORS requests. Check the response headers to confirm that the Access-Control-Allow-Origin header is set correctly and only allows the specified origin.

    For more detailed guidance on configuring CORS in Azure API Management, please refer to the official documentation here:

    https://learn.microsoft.com/en-us/azure/api-management/api-management-policies

    By following these steps, you should be able to effectively manage your CORS policy and ensure that only the specified domain can make requests. If you continue to experience issues, please let me know, and we can explore further options together.

    0 comments No comments

  2. J, Munna Lal 0 Reputation points
    2025-01-22T12:48:40.8166667+00:00

    Hi Team,We have tested the application in browser after modified the CORS inbound policy to not accept the inbound connections except selected domain URLs.

    ie , we have added https://companyabcproducts.atlassian.net/ in the CORS inbound policy and our expectation is, from above URL only the connections to be admitted and established.

    But, other URL requests also being accepted through the API management.

    Because of this our JIRA webhook modificaitons are getting reflected in the destination application.

    Please share if any other options are available for enabling the CORS policy and to validate the same.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.