Azure / Azure/azure-functions-host

Custom Headers Not Applied in Azure Function App Settings

Open
#10,557 2 comments 0 reactions 0 assignees View on GitHub
Needs: Attention :wave:
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 10h
Merged PRs (30d)
36

Description

### Is your question related to a specific version? If so, please specify:
Azure Functions (linux) - Runtime version: `4.636.0.0`

### What language does your question apply to? (e.g. C#, JavaScript, Java, All)
We're using C# - although this may apply to All languages as it relates to the configuration of HTTP headers using `host.json` and Application Settings.

### Question
I am trying to [override `host.json values](https://learn.microsoft.com/en-us/azure/azure-functions/functions-host-json#override-hostjson-values) configure custom HTTP headers for my Azure Function App via app settings, but I am not seeing the headers in the HTTP response. I have attempted the following approaches:
1. Adding a custom header `XCustomHeader` using the key `AzureFunctionsJobHost__extensions__http__customHeaders_XCustomHeader` with a value of `TestHeaderValue`, but this header is not present in the response.

2. Using key `AzureFunctionsJobHost__extensions__http__customHeaders` with an escaped JSON as the value

Despite these efforts, none of the custom headers are reflected in the response.

Is there a limitation in how the Azure Functions platform processes these headers when defined in app settings?

### Steps to reproduce
1. Add the following app setting in the Azure Portal using **Advanced Edit**:
- Method 1:
```json
{
"name": "AzureFunctionsJobHost__extensions__http__customHeaders_XCustomHeader",
"value": "TestHeaderValue",
"slotSetting": false
}
```
- Method 2:
```json
{
"name": "AzureFunctionsJobHost__extensions__http__customHeaders",
"value": "{\"Content-Security-Policy\": \"default-src 'self';\", \"Permissions-Policy\": \"accelerometer=(), autoplay=();\"}",
"slotSetting": false
}
```
2. Save the configuration and restart the Function App.
3. Navigate to the function app

#### Expected behavior
The custom headers (XCustomHeader, Content-Security-Policy, etc.) should be present in the HTTP response.

#### Actual behavior
None of the custom headers are applied to the response

Contributor guide

Open the contributing guide

Research direction

Start with the linked host.json override documentation and compare the two Azure portal app-setting formats described in the reproduction steps. Trace how the Azure Functions host processes customHeaders from application settings; done means establishing whether the configuration is supported and documenting or correcting the behavior so the expected response headers are applied.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.