Azure / Azure/azure-functions-host

AzureFunctions Proxy x-ms-privatelink-id causing invalid header value check

Open
#6,013 4 comments 2 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

When function is routed through Azure Functions Proxy, a x-ms-privatelink-id header value is added.

This header value has invalid characters

"x-ms-privatelink-id":"\n\nrequest-id\u00123|50e85f514b894e43945890308a5081ab.029e71f938874c4d."

Which fails "fetch-node" 's Headers validation check.

#### Investigative information

Please provide the following:

- Timestamp:
- Function App version:
- Function App name:
- Function name(s) (as appropriate):
- Invocation ID:
- Region:

#### Repro steps

Provide the steps required to reproduce the problem:

````
import { AzureFunction, Context, HttpRequest } from "@azure/functions"
import { Headers } from "node-fetch"

const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise {
context.log('HTTP trigger function processed a request.');

context.log( JSON.stringify(req.headers) );

let h = new Headers(req.headers);

context.log( JSON.stringify(h) );

const name = (req.query.name || (req.body && req.body.name));
const responseMessage = name
? "Hello, " + name + ". This HTTP triggered function executed successfully."
: "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";

context.res = {
// status: 200, /* Defaults to 200 */
body: responseMessage
};
};

export default httpTrigger;
````

#### Expected behavior

Provide a description of the expected behavior.

When function is called directly - no issues.
When function is called through an AzureFunctions proxy - no issues.

#### Actual behavior

Provide a description of the actual behavior observed.

When function is called through an AzureFunctions proxy - fails with

2020-05-07T08:25:32.807 [Information] {"accept":"*/*","accept-encoding":"gzip","cache-control":"no-cache","connection":"Keep-Alive","content-length":"0",
...
,"x-ms-privatelink-id":"\n\nrequest-id\u00123|50e85f514b894e43945890308a5081ab.029e71f938874c4d.","traceparent":"00-50e85f514b894e43945890308a5081ab-029e71f938874c4d-00","x-arr-ssl":"2048|256|C=US, S=Washington, L=Redmond, O=Microsoft Corporation, OU=Microsoft IT, CN=Microsoft IT TLS CA 5|CN=*.azurewebsites.net","x-appservice-proto":"https"}
2020-05-07T08:25:33.293 [Error] Executed 'Functions.testRedirect' (Failed, Id=a704c0e8-ad73-4878-89ac-df4e67de962d)
Result: Failure
Exception: TypeError:

request-id3|50e85f514b894e43945890308a5081ab.029e71f938874c4d. is not a legal HTTP header value
Stack: TypeError:

request-id3|50e85f514b894e43945890308a5081ab.029e71f938874c4d. is not a legal HTTP header value
at validateValue (D:\home\site\wwwroot\node_modules\node-fetch\lib\index.js:677:9)
at Headers.append (D:\home\site\wwwroot\node_modules\node-fetch\lib\index.js:829:3)
at new Headers (D:\home\site\wwwroot\node_modules\node-fetch\lib\index.js:754:11)
at Object. (D:\home\site\wwwroot\dist\testRedirect\index.js:17:17)
at Generator.next ()
at D:\home\site\wwwroot\dist\testRedirect\index.js:8:71
at new Promise ()
at __awaiter (D:\home\site\wwwroot\dist\testRedirect\index.js:4:12)
at Object.httpTrigger [as default] (D:\home\site\wwwroot\dist\testRedirect\index.js:14:12)
at D:\Program Files (x86)\SiteExtensions\Functions\2.0.13351\workers\node\worker-bundle.js:18808:26

#### Known workarounds

Provide a description of any known workarounds.

Don't use Node-Fetch? But this is a depedency of ApolloServer for AzureFunctions that I can't remove.

#### Related information

Provide any related information

This appears to be a most recent bug that started happening on 2020-05-06

Tried to remove x-ms-privatelink-id in AzureFunctions Proxy config, but it comes back regardless.

Contributor guide

Open the contributing guide

Research direction

Start with the Azure Functions Proxy path and the sample testRedirect entry point, then compare the logged headers with node_modules/node-fetch/lib/index.js where Headers validation fails. Done means the proxied request no longer causes the invalid x-ms-privatelink-id value to fail header construction, with the behavior verified against the supplied reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, node.js, typescript
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.