Azure / azure-relay-bridge

Azure Relay Bridge - A cross-platform command line tool to create VPN-less TCP tunnels from and to anywhere
MIT License
121 stars 48 forks source link

Added Cloud Events media type header support #88

Closed robece closed 2 months ago

robece commented 3 months ago

This commit removes the error when forwarding requests with application/cloudevents+json; charset=utf-8 content media format, and the vulnerability issue with the Azure.Identity SDK.

clemensv commented 2 months ago

@robece

This is not fixing the actual bug. The actual bug is that the input isn't a media type but a content type with arguments and that causes MediaTypeHeaderValue to fail parsing on the argument.

Minimal repro:

using System.Net.Http.Headers;
using System.Net.Mime;

var requestMessage = new HttpRequestMessage();
requestMessage.Content = new StreamContent(new MemoryStream());
var contentType = "application/cloudevents+json; charset=utf-8";
requestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);

If you drop the "charset" clause, it succeeds. A fix for this might be to adapt the code for MediaTypeHeaderValue to like the input, which requires running this through the ContentType parser and then passing the media type and charset separately.

The persisting issue is that it would then strip other parameters, which means that the way to side step all of this is to simply add the content type header differently:

requestMessage.Content.Headers.Add("Content-Type", contentType);

I'll close this PR and open a new one with that simple fix. Also, please file an issue before you submit a PR. I didn't see your actual error message anywhere here.