Cannot modify the request headers and cookies when using a custom endpoint
See original GitHub issueI am using the AppInsights tracking in a React application. This is my setup
- I cannot expose the connectionString as a configuration in the React application, because this means everybody reading my React code will have my connections string.
- I have created a separate proxying microservice and I send the tracking data to it
const appInsights = new ApplicationInsights({
config: {
instrumentationKey: 'TO_BE_HANDLED_BY_BACKEND',
disableInstrumentationKeyValidation: true,
endpointUrl: configApi.msApplicationInsigts.trackUrl
}
})
- I still want to secure my microservice and prevent misuse. I am limited to company internal rules, so in the requests, I am always sending: 3.1. Secure authentication cookie 3.2. Special header config value that complements the cookie
- The above setup works fine when I use fetch() method.
With the current setup defined, my Application Insights tracking is not working, because I am not able to modify the outgoing request. I have found addTelemetryInitializer which gives me access to the request payload but I need to be able to configure the outgoing request, similar to how I am able to modify the fetch:
const options: RequestInit = {
credentials: 'include',
mode: 'cors',
headers: {
'X-Custom-Header': 'value'
}
}
return fetch(url, options)
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Set cookies for cross origin requests - Stack Overflow
I am setting request and response headers now like crazy now, making sure that they are present in both the request and the...
Read more >Pass custom headers through API Gateway to a Lambda ...
I want to configure an AWS Lambda function through custom (non-proxy) integration to process custom headers that are passed through my Amazon ...
Read more >HTTP header manipulation - Envoy Proxy
The output is an empty string, because request headers are modified before the request is sent upstream and the response is not received...
Read more >Cross-Origin Resource Sharing (CORS) - MDN Web Docs
Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism ... as Cookies and HTTP Authentication) should be sent with requests.
Read more >Using cookies - Postman Learning Center
You can't override cookie headers directly in the Headers tab. Edit the cookie in the cookie manager, or delete the cookie and set...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, there are a couple of things here
So having said above, let me provide an approach that you might be able to implement as we do understand the concerns you are talking about.
InstrumentProto()
helper that you could use to provide a callback that would allow you to add the additional headers.You don’t need to call the base function as these helpers “wrap” the calls so the “real” function is still called after the hooked request.
The implementations are here https://github.com/microsoft/ApplicationInsights-JS/blob/master/shared/AppInsightsCore/src/JavaScriptSDK/InstrumentHooks.ts I couldn’t find any documentation, but the internal usage is located here https://github.com/microsoft/ApplicationInsights-JS/blob/master/extensions/applicationinsights-dependencies-js/src/ajax.ts#L469
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.