Skip to content

user-agent header control #37

Closed
Closed

Description

@annevk

Should fetch() set user-agent by default? Allow appending bytes? Allow replacing it? Allow it to be omitted?

See w3c/ServiceWorker#348 (comment) for context.

And why is it on the forbidden header list? It has been since forever, but is there strong rationale?

Activity

  1. hallvors commented on Apr 5, 2015

    @hallvors

    I think we 'inherited' User-Agent from a list of headers Flash disallowed changing in its implementation. There was some speculation that some services might exist that only allowed specific customized browsers to access them, using UA string as a sort of auth token, but I don't think anybody ever found a real-life case of such a system. (Obviously it would be astonishingly poor design).

    Personally, I think we can and should drop User-Agent from the list of headers you're not allowed to set.

  2. annevk commented on Apr 5, 2015

    @annevk
    MemberAuthor

    If we allow setting it to any value and effectively replace anything the user agent would set we should probably make it a parameter of RequestInit as the supplied headers argument combines with existing headers (and never replaces). So e.g.

    fetch(url, {userAgent: "Hi"})
    
  3. hallvors commented on Apr 5, 2015

    @hallvors

    (It might be worth noting that GitHub itself recommends User-Agent set to your GH user name in API requests - this is of course trivial if you write Python/Node/whatever clients, but not currently possible from an API consumer running in a browser. So there's a big and important use case right here.)

  4. domenic commented on Apr 5, 2015

    @domenic
    Member

    If we allow setting it to any value and effectively replace anything the user agent would set we should probably make it a parameter of RequestInit as the supplied headers argument combines with existing headers (and never replaces). So e.g.

    Hmm, I'm not sure I necessarily agree. It seems a straightforward extension to say that headers provided by the RequestInit overwrite default headers. What do you think would be confusing about allowing User-Agent to be set through the normal mechanisms?

  5. dgraham commented on Apr 5, 2015

    @dgraham

    GitHub itself recommends User-Agent set to your GH user name in API requests

    https://developer.github.com/v3/#user-agent-required

    This helps us contact application owners when there are problems, like a rogue script making lots of API calls. However, many API resources are only available to authenticated sessions, so the user account is already known. And when accessing the API through a browser, the CORS request includes the Origin header.

    The User-Agent header guidance in the API is helpful, but it's not necessarily an example for or against this capability being added to fetch.

  6. dgraham commented on Apr 5, 2015

    @dgraham

    If User-Agent is allowed to be assigned, I think the expected usage would be to pass it in with the rest of the headers for the request.

    fetch('/users', {
      headers: {
        'User-Agent': 'Web/2.0',
        'Accept': 'application/json'
      }
    })
  7. annevk commented on Apr 5, 2015

    @annevk
    MemberAuthor

    I guess that might be okay as well. We could have a step in https://fetch.spec.whatwg.org/#http-network-fetch that appends it if it is not already present in HTTPRequest's header list.

  8. annevk commented on Apr 6, 2015

    @annevk
    MemberAuthor

    So actually, the reason you want it to be an argument rather than part of headers is so you can force it to be omitted.

  9. annevk commented on Apr 6, 2015

    @annevk
    MemberAuthor
  10. domenic commented on Apr 6, 2015

    @domenic
    Member

    So actually, the reason you want it to be an argument rather than part of headers is so you can force it to be omitted.

    Can you expand on this? I don't quite understand why one location or the other would matter for this, or why you would force it to be omitted.

  11. annevk commented on Apr 6, 2015

    @annevk
    MemberAuthor

    If we offer customization, I think it would make sense to also offer omitting it altogether e.g. to reduce the size of the request or debug a server. The location matters since by default it is included and the Headers class is not an instruction set but rather a list of headers included in the request.

  12. domenic commented on Apr 6, 2015

    @domenic
    Member

    Oh, I see!

    Would it be conceivable not to set the header by default at all? Hmm, probably not very good, I'm being too Node-influenced here...

    So how would you omit it? omitUserAgent: true? userAgent: null?

  13. annevk commented on Apr 6, 2015

    @annevk
    MemberAuthor

    null was my idea, since undefined already means doing the default, which is to include it and seems highly unlikely to change.

  14. domenic commented on Apr 6, 2015

    @domenic
    Member

    Why would userAgent: null be good, but 'User-Agent': null not be good?

    Related question: when you do const h = new Headers(), does h.get("User-Agent") return something? Why or why not?

  15. annevk commented on Apr 6, 2015

    @annevk
    MemberAuthor

    "User-Agent": null === "User-Agent": "null". new Headers() creates an empty multimap, it is not populated in any way.

  16. 19 remaining items

  17. mnot commented on Apr 9, 2015

    @mnot
    Member

    .02 - it sure would be nice if UA could be appended to, so you can add "mywidget/1.0" or "(test 3)" for example, rather than blowing the entire thing away.

    Syntax here:
    http://httpwg.github.io/specs/rfc7231.html#header.user-agent

  18. domenic commented on Apr 9, 2015

    @domenic
    Member

    navigator.userAgent + 'my string'

  19. annevk commented on May 7, 2015

    @annevk
    MemberAuthor

    @sicking I don't understand why omitting the header altogether is a cause for concern. It wasn't when we stopped sending Referer.

  20. annevk commented on Jul 17, 2015

    @annevk
    MemberAuthor

    I'm inclined to define 1 in #37 (comment) but leave the omitUserAgent feature out for now since that is harder to tackle (unless @sicking is wrong and it should not require explicit opt-in to omit it).

  21. annevk commented on Jul 29, 2015

    @annevk
    MemberAuthor

    If we need omitUserAgent please file a new issue. Ideally reach out to user agents for their security requirements, since they're not entirely clear to me.

  22. dandv commented on Jun 17, 2020

    @dandv

    Is User-Agent still forbidden after dab09b0 ?

  23. annevk commented on Jun 18, 2020

    @annevk
    MemberAuthor

    It's not as per this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions