Configuring CORS policies for the 1C-Bitrix API

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1177
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Setting Up CORS Policy for 1C-Bitrix API

CORS (Cross-Origin Resource Sharing) is a browser security mechanism that restricts cross-origin HTTP requests. When building APIs for 1C-Bitrix accessed from different domains or subdomains, proper CORS configuration is essential.

CORS Fundamentals

Browser sends Origin header with every request. Server responds with Access-Control-Allow-Origin header indicating which origins can access the resource. Without proper headers, browser blocks the response.

Implementation in Bitrix

Add CORS headers to API responses:

header("Access-Control-Allow-Origin: https://example.com");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Headers: Content-Type, Authorization");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 86400");

For preflight OPTIONS requests, return 200 with CORS headers before processing actual request.

Configuration Strategies

Single Domain: Allow specific domain only.

Wildcard: Allow all origins (not recommended for sensitive APIs):

Access-Control-Allow-Origin: *

Dynamic: Check origin against whitelist at runtime.

Credentials and Security

Set Access-Control-Allow-Credentials: true to allow cookies/auth headers. Avoid using wildcard with credentials—only specific origins allowed.

Common Issues

  • Preflight Fails: Missing OPTIONS handler—implement to return CORS headers.
  • Credentials Blocked: Credentials require explicit origin (not wildcard).
  • Cache Issues: CORS headers cached; clear cache if changing configuration.

Best Practices

  • Only allow necessary origins.
  • Use specific methods (GET, POST) instead of all methods.
  • Limit allowed headers to what's needed.
  • Use HTTPS for credential-bearing requests.
  • Set appropriate max-age to reduce preflight requests.

Proper CORS configuration balances security and functionality. Too restrictive breaks integrations; too permissive creates security risks.