Flask-UA-Enricher


NameFlask-UA-Enricher JSON
Version 0.0.1 PyPI version JSON
download
home_pagehttps://github.com/agentzex/flask-Sec-CH-UA
SummaryDecorates flask views and enrich User-Agent header in case of reduced UA string
upload_time2023-07-25 04:34:57
maintainer
docs_urlNone
authoragentzex
requires_python>=3.6
licenseMIT
keywords flask flask-ua flask-ua-enricher flask-sec-ch-ua flask-useragent-enrich flask-useragent-enricher flask-sec-ua useragent-enricher
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
## Why it's needed

Starting Chrome 110 (https://developer.chrome.com/blog/user-agent-reduction-android-model-and-version/), Chrome reduced User-Agent string content sent by default by browsers in every request.
The new UA string is will look like this:

Before: user-agent includes Android version and device model:

``` Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.0.0 Mobile Safari/537.36 ```

After: reduced user-agent with fixed Android version and device model:

``` Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.0.0 Mobile Safari/537.36 ```


This Flask wrapper tries to fix this by decorating a chosen Flask view, and if the fixed Android version and model are observed, it will trigger a refresh request from the browser but with the high entropy sec-ch-ua HTTP headers in the response, that can give us more information about the client (device model, OS version etc).

  (You can read more about those Sec-CH-UA headers here https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/getHighEntropyValues)

The response from the browser after the resent request will then have an enriched Flask request.user_agent including the correct device model and Android version, that can also be later parsed in any standard user-agent parsers libs or APIs


## Quickstart

```
from flask import Flask, request
from flask_ua_enricher import SecChUa, resend_request_with_ch_ua

app = Flask(__name__)

sec_ch_ua = SecChUa()
sec_ch_ua.init_app(app)


@app.route('/helloChrome', methods=['GET'])
@resend_request_with_ch_ua
def hello():
    return f"Hello with enriched UA: {request.user_agent.string}" 
```


## Note

If you're running this in a dev environment (i.e. your local PC), make sure to run your Flask server with HTTPS otherwise the enrichment won't work



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/agentzex/flask-Sec-CH-UA",
    "name": "Flask-UA-Enricher",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "flask,flask-ua,flask-ua-enricher,flask-Sec-CH-UA,flask-useragent-enrich,flask-useragent-enricher,flask-sec-ua,useragent-enricher",
    "author": "agentzex",
    "author_email": "cypy919@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/06/d3/c18b27ddad896e12f20868ac9b7f1ce512d32a5decab67c84bfc301d554c/Flask-UA-Enricher-0.0.1.tar.gz",
    "platform": "any",
    "description": "\r\n## Why it's needed\r\n\r\nStarting Chrome 110 (https://developer.chrome.com/blog/user-agent-reduction-android-model-and-version/), Chrome reduced User-Agent string content sent by default by browsers in every request.\r\nThe new UA string is will look like this:\r\n\r\nBefore: user-agent includes Android version and device model:\r\n\r\n``` Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.0.0 Mobile Safari/537.36 ```\r\n\r\nAfter: reduced user-agent with fixed Android version and device model:\r\n\r\n``` Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.0.0 Mobile Safari/537.36 ```\r\n\r\n\r\nThis Flask wrapper tries to fix this by decorating a chosen Flask view, and if the fixed Android version and model are observed, it will trigger a refresh request from the browser but with the high entropy sec-ch-ua HTTP headers in the response, that can give us more information about the client (device model, OS version etc).\r\n\r\n  (You can read more about those Sec-CH-UA headers here https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/getHighEntropyValues)\r\n\r\nThe response from the browser after the resent request will then have an enriched Flask request.user_agent including the correct device model and Android version, that can also be later parsed in any standard user-agent parsers libs or APIs\r\n\r\n\r\n## Quickstart\r\n\r\n```\r\nfrom flask import Flask, request\r\nfrom flask_ua_enricher import SecChUa, resend_request_with_ch_ua\r\n\r\napp = Flask(__name__)\r\n\r\nsec_ch_ua = SecChUa()\r\nsec_ch_ua.init_app(app)\r\n\r\n\r\n@app.route('/helloChrome', methods=['GET'])\r\n@resend_request_with_ch_ua\r\ndef hello():\r\n    return f\"Hello with enriched UA: {request.user_agent.string}\" \r\n```\r\n\r\n\r\n## Note\r\n\r\nIf you're running this in a dev environment (i.e. your local PC), make sure to run your Flask server with HTTPS otherwise the enrichment won't work\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Decorates flask views and enrich User-Agent header in case of reduced UA string",
    "version": "0.0.1",
    "project_urls": {
        "Homepage": "https://github.com/agentzex/flask-Sec-CH-UA"
    },
    "split_keywords": [
        "flask",
        "flask-ua",
        "flask-ua-enricher",
        "flask-sec-ch-ua",
        "flask-useragent-enrich",
        "flask-useragent-enricher",
        "flask-sec-ua",
        "useragent-enricher"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "000bc2357b590982ca922ad43be8642196c2068e7f86846878c316f94eacd4da",
                "md5": "4f005cbe8d8e8be37a3f06f0602fe796",
                "sha256": "3396b87c686e4597ddce2643756fba5e7e7f2c44a471529d87052766df501803"
            },
            "downloads": -1,
            "filename": "Flask_UA_Enricher-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4f005cbe8d8e8be37a3f06f0602fe796",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 4467,
            "upload_time": "2023-07-25T04:34:56",
            "upload_time_iso_8601": "2023-07-25T04:34:56.731632Z",
            "url": "https://files.pythonhosted.org/packages/00/0b/c2357b590982ca922ad43be8642196c2068e7f86846878c316f94eacd4da/Flask_UA_Enricher-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "06d3c18b27ddad896e12f20868ac9b7f1ce512d32a5decab67c84bfc301d554c",
                "md5": "8e5138bae7e46894eb8dfd3a186a7429",
                "sha256": "44d13e9aec2c7ce34686e9ac0668d407e134b44c57282ce68f090b2f0d9d4acc"
            },
            "downloads": -1,
            "filename": "Flask-UA-Enricher-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8e5138bae7e46894eb8dfd3a186a7429",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 3915,
            "upload_time": "2023-07-25T04:34:57",
            "upload_time_iso_8601": "2023-07-25T04:34:57.875648Z",
            "url": "https://files.pythonhosted.org/packages/06/d3/c18b27ddad896e12f20868ac9b7f1ce512d32a5decab67c84bfc301d554c/Flask-UA-Enricher-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-25 04:34:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "agentzex",
    "github_project": "flask-Sec-CH-UA",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "flask-ua-enricher"
}
        
Elapsed time: 0.09740s