Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to set User-Agent #424

Open
bladerunner2020 opened this issue May 31, 2023 · 4 comments
Open

Possibility to set User-Agent #424

bladerunner2020 opened this issue May 31, 2023 · 4 comments

Comments

@bladerunner2020
Copy link

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?

@gautamsi
Copy link
Owner

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.

@bladerunner2020
Copy link
Author

Ok, thanks. Will try to patch.

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

@gautamsi
Copy link
Owner

gautamsi commented Jun 1, 2023

This is based on original c# code by microsoft

@bladerunner2020
Copy link
Author

bladerunner2020 commented Jun 1, 2023

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



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants