Coder Social home page Coder Social logo

Add User-Agent sniffing about sxg-rs HOT 6 CLOSED

twifkak avatar twifkak commented on June 2, 2024
Add User-Agent sniffing

from sxg-rs.

Comments (6)

twifkak avatar twifkak commented on June 2, 2024 1

Oh, thanks for the investigation @antiphoton. I overestimated the degree to which UA strings can be accurately parsed. I'll withdraw my earlier comment (except to be mindful of more than two digits).

Maybe something like " Chrome/" or " Chromium/" (note the leading space) followed by any number of digits? No need for regex then, I suppose? std::string or nom will probably suffice?

from sxg-rs.

twifkak avatar twifkak commented on June 2, 2024

This should be a "denylist" approach -- allowing all user agents except those that match Chromium 73-78.

from sxg-rs.

twifkak avatar twifkak commented on June 2, 2024

I found a few UA parsers in crates, in descending popularity:

We should rule out the huge ones, since we have serverless bundle size constraints.

Perhaps a regex will suffice for our needs? Famous last words.

from sxg-rs.

quangIO avatar quangIO commented on June 2, 2024

I think a small heuristic without regex should be the way to go. For example, find Chrome/ or Chromium/ then get the next 2 digits to see if it is in [73, 78] range.

from sxg-rs.

twifkak avatar twifkak commented on June 2, 2024

Perhaps I'm a bit too forward-looking but there may eventually be a Chrome 730. 😉

Are you concerned around new dependencies because of bundle size, security, performance, or something else?

In general, I prefer accurate parsers because inaccurate ones lead to weird ecosystem effects:

  1. sites begin to target bugs in the parsers, either deliberately (e.g. the IE star hack) or accidentally, and then
  2. changes to the standard need to keep in mind backwards-compatibility with these hacks, and then
  3. the semantics get progressively more complex (e.g. HTML adoption agency algorithm and others leading to cases where you can construct invalid DOMs)

That said, I'm also a pragmatist. In particular, sxg-rs is a drop in the bucket -- it probably won't materially effect the destiny of User-Agent. 😁 So if a small heuristic is preferable, that's fine.

from sxg-rs.

antiphoton avatar antiphoton commented on June 2, 2024

user-agent-parser, uap-rust and fast_uapperser are all internally using regular expressions defined in uap-core.

Picking the Chrome-related regex in uap-core is suffice to parse the Chrome major version.

However, adding regex crate as dependency increases the gzipped WASM size from 737 kB to 954 kB.

from sxg-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.