Skip to main content

Cross-Origin Resource Sharing (CORS)

Overview​

The CORS (Cross-Origin Resource Sharing) Policy controls how resources on a server can be accessed from different origins. It is crucial for web applications that rely on APIs hosted on different domains. The CORS policy ensures secure cross-origin requests by defining allowed methods, headers, credentials, and caching behavior.

Configuration Details​

The CORS Policy includes several key settings that control access and security:

FieldDescriptionExample ValuesNotes
methodsDefines allowed HTTP methods.GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS, TRACE, CONNECTUse * to allow all methods.
originsSpecifies the allowed origins (domains).https://www.example.com:8000, https://www.google.com:80Use * to allow all origins.
allowHeadersLists the allowed request headers.x-apim-key, Content-TypeUse * to allow all headers.
exposedHeadersDefines headers that should be exposed to the client.Content-Length, X-My-Custom-Header, X-Another-Custom-HeaderUse * to expose all headers.
allowCredentialDetermines if credentials (cookies, authentication) are allowed.true / falseIf true, * cannot be used in origins or allowHeaders. Default: false.
maxAgeDuration (in seconds) that the preflight request is cached.3600Default: 3600 (1 hour).

Note:

  • Avoid using in origins unless necessary to prevent security risks.
  • Set allowCredential to false if authentication credentials are not required.
  • Only expose necessary headers in exposedHeaders.
  • Increase maxAge to reduce unnecessary preflight requests.
  • Limit the allowed methods and headers to only what is needed.