Bylaw

Gallery › Healthcare APIs › Azure built-in policies

CORS should not allow every domain to access your FHIR Service

Converted Policy Audit Disabled Mode Indexed Version 1.1.0

Cross-Origin Resource Sharing (CORS) should not allow all domains to access your FHIR Service. To protect your FHIR Service, remove access for all domains and explicitly define the domains allowed to connect.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONFHIR_Service_RestrictCORSAccess_Audit.json · 57 lines
{
  "properties": {
    "displayName": "CORS should not allow every domain to access your FHIR Service",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Cross-Origin Resource Sharing (CORS) should not allow all domains to access your FHIR Service. To protect your FHIR Service, remove access for all domains and explicitly define the domains allowed to connect.",
    "metadata": {
      "version": "1.1.0",
      "category": "Healthcare APIs"
    },
    "version": "1.1.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "audit",
          "Audit",
          "disabled",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.HealthcareApis/workspaces/fhirservices"
          },
          {
            "count": {
              "field": "Microsoft.HealthcareApis/workspaces/fhirservices/corsConfiguration.origins[*]",
              "where": {
                "field": "Microsoft.HealthcareApis/workspaces/fhirservices/corsConfiguration.origins[*]",
                "equals": "*"
              }
            },
            "greater": 0
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/fe1c9040-c46a-4e81-9aea-c7850fbb3aa6",
  "name": "fe1c9040-c46a-4e81-9aea-c7850fbb3aa6"
}
Bylawfe1c9040-c46a-4e81-9aea-c7850fbb3aa6.bylaw.ps1 · 30 lines
# Converted from FHIR_Service_RestrictCORSAccess_Audit.json by ConvertTo-Bylaw.
Policy 'fe1c9040-c46a-4e81-9aea-c7850fbb3aa6' {

    Properties @{
        DisplayName   = 'CORS should not allow every domain to access your FHIR Service'
        Description   = 'Cross-Origin Resource Sharing (CORS) should not allow all domains to access your FHIR Service. To protect your FHIR Service, remove access for all domains and explicitly define the domains allowed to connect.'
        Version       = '1.1.0'
        Category      = 'Healthcare APIs'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('audit', 'Audit', 'disabled', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.HealthcareApis/workspaces/fhirservices' {

        Require 'corsConfiguration.origins is as required' {
            Each 'corsConfiguration.origins[*]' {
                Element | Must -Not -Be '*'
            }
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Healthcare APIs/FHIR_Service_RestrictCORSAccess_Audit.json in Azure/azure-policy, under the MIT licence.