-
-
Notifications
You must be signed in to change notification settings - Fork 76
Add default user-agent + enable custom one #226
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
Conversation
Uzlopak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont like the idea to expose unnecessary information in security context. Also this is not a browser.
Can you elaborate? It's a SHOULD in the HTTP spec and common good practice?
User agent is the term for any HTTP client, see: https://www.rfc-editor.org/rfc/rfc9110#name-user-agents |
|
I actually dont see any gain from this. Only exposing information. We also dont send in other plugins any user agent. I think this is a semver major if we by default send user agent. Imho by default dont send user agent is the best, but still i dont think it is good decision to add this feature. |
|
@Uzlopak How about doing like Seems to be what
Though |
|
Yes, setting it to fixed value without require etc. is definetly better. I would prefer that any time. |
|
Some more points of reference:
@Uzlopak Is this as a reply to #226 (comment) ? |
|
I would set the user agent to 'fastify-oauth2'. |
|
@Uzlopak Done ✔️ I can get behind that, especially considering that it appears to be the common practice in the npm ecosystem nowadays 👍 |
Every library appends their user-agent to the one that's been set at a level above them. Hence any provided user-agent comes before the default user agent. To provide context, the version number of `@fastify/oauth2` + the home page of it is included in the User-Agent. That way an API can diagnose possibly faulty consumers and file an issue. If someone wouldn't want to expose this, they can always set a custom User-Agent header directly in the http settings. Especially if fastify#225 gets merged.
Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
4a8b663 to
cb1a992
Compare
|
Rebased to do #226 (comment) |
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
index.js
Outdated
| } = options | ||
|
|
||
| const userAgent = options.userAgent | ||
| ? `${options.userAgent} ${USER_AGENT}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you can not truely override the useragent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected more something like
let userAgent = {}
switch (options.userAgent) {
case false:
break
case undefined:
userAgent['User-Agent'] = USER_AGENT
break
default:
userAgent['User-Agent'] = options.userAgent
break
}
const credentials = {
...options.credentials,
http: {
...options.credentials.http,
headers: {
...userAgent,
...options.credentials.http?.headers
}
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you can not truely override the useragent?
You can, if you override the http settings
On other comment:
I prefer using const over let and avoid switch unless checking one bar against multiple values (as a missing break can cause havoc and it’s a bit unusual in that body of a case doesn’t come with its own scope, unless you add one, so it’s easy for people to make mistakes with)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I set userAgent to "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)", then the plugin is changing the useragent to: "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0) fastify/oauth2"
So how can I override the useragent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Uzlopak This is what the RFC 9110 says, my emphasis:
The User-Agent field value consists of one or more product identifiers, each followed by zero or more comments (Section 5.6.5), which together identify the user agent software and its significant subproducts. By convention, the product identifiers are listed in decreasing order of their significance for identifying the user agent software. Each product identifier consists of a name and optional version.
This is what this PR up to now has done + I have added tests + comments on how to override it if one wants to.
But to avoid confusion I have now removed such prepending of the additional user-agent and instead outright replaces the default one. Removes possibly valuable information but I hope that fixes your concerns.
The RFC 9110 states: "The User-Agent field value consists of one or more product identifiers, each followed by zero or more comments (Section 5.6.5), which together identify the user agent software and its significant subproducts. By convention, the product identifiers are listed in decreasing order of their significance for identifying the user agent software." But since many are not aware of it, it may be better to remove it
Uzlopak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The RFC9110 HTTP Semantics spec says:
So I think we should.
Convention is that a library appends their user-agent to the one that's been set at the level above them, hence the user provided user-agent comes before the default one set in this module.To provide context, the version number of this module + the home page of it is included in the User-Agent. That way an API can diagnose possibly faulty consumers and file an issue.If someone wouldn't want to expose that info in a header, they can always set a custom User-Agent header directly in the http settings. Especially if #225 gets merged.
Checklist
npm run testandnpm run benchmarkand the Code of conduct