ews-javascript-api icon indicating copy to clipboard operation
ews-javascript-api copied to clipboard

Possibility to set User-Agent

Open bladerunner2020 opened this issue 2 years ago • 4 comments
trafficstars

We need to set User-Agent for our project as it's required by customer security policy.

In ExchangeSerivceBase.js there is a line that set User-Agent but it is commented out:

// request.headers["User-Agent"] = this.UserAgent || ExchangeServiceBase.defaultUserAgent; //todo:fix -> Noje.js is refusing to set this unsafe header -//

I tried to uncomment it and it seems working fine. At least I got no errors and I can see that the header is set (using override(https) to hijack requests sent, will try wireahark later).

Would it be possible to restore this feature?

Another question if I set user-agent using ExchangeService.UserAgent = 'my-user-agent' it adds ...(ExchangeService/undefined):

  set UserAgent(value: string) {
    this.userAgent = `${value} (${ExchangeServiceBase.defaultUserAgent})`;
  }

why?

bladerunner2020 avatar May 31 '23 14:05 bladerunner2020

because the value for EwsUtilities.BuildVersion is not assigned,

before running anything, somewhere in code call EwsUtilities.BuildVersion = 'default_build_version';, it should then get you ExchangeService/default_build_version.

you can use your custom string there.

I can add this to next iteration, no promise on release timeline. you can however use patch-packages npm package to let you fix this for now.

gautamsi avatar May 31 '23 16:05 gautamsi

Ok, thanks. Will try to patch.

I have a stupid question: why don't let set the UserAgent string arbitrarily?

bladerunner2020 avatar Jun 01 '23 06:06 bladerunner2020

This is based on original c# code by microsoft

gautamsi avatar Jun 01 '23 06:06 gautamsi

I uncommented the line where the user agent is added to the header and in my code I added this line:

EwsUtilities.BuildVersion = 'MY-AGENT';

I got this header:

user-agent:
'ExchangeServicesClient/MY-AGENT (ExchangeServicesClient/undefined)'

So I think the setting user agent should be modified as well. Will do it using patch-module.

PS If I set

ExchangeServiceBase.defaultUserAgent = 'MY-AGENT';

then I got: user-agent: 'ExchangeServicesClient/MY-AGENT (ExchangeServicesClient/'MY-AGENT)'


Thanks



bladerunner2020 avatar Jun 01 '23 07:06 bladerunner2020