Merge branch '3.0.x'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parents 98a7f9f, 87d5f5b · Browse files · 37 files·+657 added−608 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
37 files+657 added−608 removed
- tests:+5 added−9 removed
- other:+652 added−599 removed
Provenance
- Commit
6ab71ed- Tree
0c19479- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
98a7f9f- Parent 2
87d5f5b
37 files changed+657 added−608 removed
modified:.devcontainer/on-create-command.sh+1 added-3 removed
1234346567#!/bin/bashset -e
python3 -m venv .venvpython3 -m venv --upgrade-deps .venv. .venv/bin/activatepip install -U pippip install -r requirements/dev.txtpip install -e .pre-commit install --install-hooksmodified:.github/ISSUE_TEMPLATE/bug-report.md+1 added-1 removed
3 unmodified lines456788910111215 unmodified lines3 unmodified lines---
<!--This issue tracker is a tool to address bugs in Flask itself. Please usePallets Discord or Stack Overflow for questions about your own code.GitHub Discussions or the Pallets Discord for questions about your own code.
Replace this comment with a clear outline of what the bug is.-->
15 unmodified linesmodified:.github/ISSUE_TEMPLATE/config.yml+6 added-6 removed
12345456789789101111blank_issues_enabled: falsecontact_links: - name: Security issue url: security@palletsprojects.com about: Do not report security issues publicly. Email our security contact. url: https://github.com/pallets/flask/security/advisories/new about: Do not report security issues publicly. Create a private advisory. - name: Questions url: https://stackoverflow.com/questions/tagged/flask?tab=Frequent about: Search for and ask questions about your code on Stack Overflow. - name: Questions and discussions url: https://github.com/pallets/flask/discussions/ about: Ask questions about your own code on the Discussions tab. - name: Questions on url: https://discord.gg/pallets about: Discuss questions about your code on our Discord chat. about: Ask questions about your own code on our Discord chat.modified:.github/workflows/lock.yaml+8 added-6 removed
12345123456789104 unmodified lines15161718181920212223name: 'Lock threads'# Lock closed issues that have not received any further activity for# two weeks. This does not close open issues, only humans may do that.# We find that it is easier to respond to new issues with fresh examples# rather than continuing discussions on old issues.name: Lock inactive closed issues# Lock closed issues that have not received any further activity for two weeks.# This does not close open issues, only humans may do that. It is easier to# respond to new issues with fresh examples rather than continuing discussions# on old issues.
on: schedule: - cron: '0 0 * * *'permissions:4 unmodified linesjobs: lock: runs-on: ubuntu-latest steps: - uses: dessant/lock-threads@1bf7ec25051fe7c00bdd17e6a7cf3d7bfb7dc771 - uses: dessant/lock-threads@7de207be1d3ce97a9abe6ff1306222982d1ca9f9 # v5.0.1 with: issue-inactive-days: 14 pr-inactive-days: 14 discussion-inactive-days: 14modified:.github/workflows/publish.yaml+15 added-13 removed
7 unmodified lines89101112131213141516174 unmodified lines222324252626272828293031323334353736373839402 unmodified lines4344454648474849505153525354555657585959606062616263646567686667686971707172737 unmodified lines runs-on: ubuntu-latest outputs: hash: ${{ steps.hash.outputs.hash }} steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 with: python-version: '3.x' cache: pip cache-dependency-path: requirements*/*.txt4 unmodified lines # Generate hashes used for provenance. - name: generate hash id: hash run: cd dist && echo "hash=$(sha256sum * | base64 -w0)" >> $GITHUB_OUTPUT - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 with: name: dist path: ./dist provenance: needs: [build] permissions: actions: read id-token: write contents: write # Can't pin with hash due to how this workflow works. uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.9.0 uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.10.0 with: base64-subjects: ${{ needs.build.outputs.hash }} create-release: # Upload the sdist, wheels, and provenance to a GitHub release. They remain2 unmodified lines runs-on: ubuntu-latest permissions: contents: write steps: - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - name: create release run: > gh release create --draft --repo ${{ github.repository }} ${{ github.ref_name }} *.intoto.jsonl/* dist/* *.intoto.jsonl/* artifact/* env: GH_TOKEN: ${{ github.token }} publish-pypi: needs: [provenance] # Wait for approval before attempting to upload to PyPI. This allows reviewing the # files in the draft release. environment: # Wait for approval before attempting to upload to PyPI. This allows reviewing the # files in the draft release. The projection is configured in the repository settings. name: publish url: https://pypi.org/project/flask/${{ github.ref_name }} url: https://pypi.org/project/Flask/${{ github.ref_name }} runs-on: ubuntu-latest permissions: id-token: write steps: - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a - uses: pypa/gh-action-pypi-publish@2f6f737ca5f74c637829c0f5c3acd0e29ea5e8bf - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - uses: pypa/gh-action-pypi-publish@68e62d4871ad9d14a9d55f114e6ac71f0b408ec0 # v1.8.14 with: repository-url: https://test.pypi.org/legacy/ - uses: pypa/gh-action-pypi-publish@2f6f737ca5f74c637829c0f5c3acd0e29ea5e8bf packages-dir: artifact/ - uses: pypa/gh-action-pypi-publish@68e62d4871ad9d14a9d55f114e6ac71f0b408ec0 # v1.8.14 with: packages-dir: artifact/modified:.github/workflows/tests.yaml+30 added-20 removed
13 unmodified lines14151617181918192021222324252627282930313233342425262728293031323334363735363738394040414243444546474849505152534354555646475758495913 unmodified lines - '*.md' - '*.rst'jobs: tests: name: ${{ matrix.name }} runs-on: ${{ matrix.os }} name: ${{ matrix.name || matrix.python }} runs-on: ${{ matrix.os || 'ubuntu-latest' }} strategy: fail-fast: false matrix: include: - {name: Linux, python: '3.12', os: ubuntu-latest, tox: py312} - {name: Windows, python: '3.12', os: windows-latest, tox: py312} - {name: Mac, python: '3.12', os: macos-latest, tox: py312} - {name: '3.11', python: '3.11', os: ubuntu-latest, tox: py311} - {name: '3.10', python: '3.10', os: ubuntu-latest, tox: py310} - {name: '3.9', python: '3.9', os: ubuntu-latest, tox: py39} - {name: '3.8', python: '3.8', os: ubuntu-latest, tox: py38} - {name: 'PyPy', python: 'pypy-3.10', os: ubuntu-latest, tox: pypy310} - {name: 'Minimum Versions', python: '3.12', os: ubuntu-latest, tox: py312-min} - {name: 'Development Versions', python: '3.8', os: ubuntu-latest, tox: py38-dev} - {name: Typing, python: '3.12', os: ubuntu-latest, tox: typing} - {python: '3.12'} - {name: Windows, python: '3.12', os: windows-latest} - {name: Mac, python: '3.12', os: macos-latest} - {python: '3.11'} - {python: '3.10'} - {python: '3.9'} - {python: '3.8'} - {name: PyPy, python: 'pypy-3.10', tox: pypy310} - {name: Minimum Versions, python: '3.12', tox: py-min} - {name: Development Versions, python: '3.8', tox: py-dev} steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 with: python-version: ${{ matrix.python }} allow-prereleases: true cache: 'pip' cache: pip cache-dependency-path: requirements*/*.txt - run: pip install tox - run: tox run -e ${{ matrix.tox || format('py{0}', matrix.python) }} typing: runs-on: ubuntu-latest steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 with: python-version: '3.x' cache: pip cache-dependency-path: requirements*/*.txt - name: cache mypy uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 with: path: ./.mypy_cache key: mypy|${{ matrix.python }}|${{ hashFiles('pyproject.toml') }} if: matrix.tox == 'typing' key: mypy|${{ hashFiles('pyproject.toml') }} - run: pip install tox - run: tox run -e ${{ matrix.tox }} - run: tox run -e typingmodified:.github/dependabot.yml+6 added
2 unmodified lines3 - package-ecosystem: github-actions4 directory: /5 schedule:6 interval: monthly7+ ignore:8+ # slsa depends on upload/download v39+ - dependency-name: actions/upload-artifact10+ versions: '>= 4'11+ - dependency-name: actions/download-artifact12+ versions: '>= 4'13 groups:14 github-actions:15 patterns:16 - '*'8 unmodified linesmodified:.github/pull_request_template.md+10 added-15 removed
1 <!--2 Before opening a PR, open a ticket describing the issue or feature the3-PR will address. Follow the steps in CONTRIBUTING.rst.3+PR will address. An issue is not required for fixing typos in4+documentation, or other simple non-code changes.5 6 Replace this comment with a description of the change. Describe how it7 addresses the linked ticket.8 -->9 10 <!--11 Link to relevant issues or previous PRs, one per line. Use "fixes" to12 automatically close an issue.13+14+fixes #<issue number>15 -->16 14-- fixes #<issue number>15-17 <!--17-Ensure each step in CONTRIBUTING.rst is complete by adding an "x" to18-each box below.18+Ensure each step in CONTRIBUTING.rst is complete, especially the following:19 20-If only docs were changed, these aren't relevant and can be removed.20+- Add tests that demonstrate the correct behavior of the change. Tests21+ should fail without the change.22+- Add or update relevant docs, in the docs folder and in code.23+- Add an entry in CHANGES.rst summarizing the change and linking to the issue.24+- Add `.. versionchanged::` entries in any relevant code docs.25 -->22-23-Checklist:24-25-- [ ] Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.26-- [ ] Add or update relevant docs, in the docs folder and in code.27-- [ ] Add an entry in `CHANGES.rst` summarizing the change and linking to the issue.28-- [ ] Add `.. versionchanged::` entries in any relevant code docs.29-- [ ] Run `pre-commit` hooks and fix any issues.30-- [ ] Run `pytest` and `tox`, no tests failed.deleted:.github/SECURITY.md-19 removed
1-# Security Policy2-3-If you believe you have identified a security issue with a Pallets4-project, **do not open a public issue**. To responsibly report a5-security issue, please email security@palletsprojects.com. A security6-team member will contact you acknowledging the report and how to7-continue.8-9-Be sure to include as much detail as necessary in your report. As with10-reporting normal issues, a minimal reproducible example will help the11-maintainers address the issue faster. If you are able, you may also12-include a fix for the issue generated with `git format-patch`.13-14-The current and previous release will receive security patches, with15-older versions evaluated based on usage information and severity.16-17-After fixing an issue, we will make a security release along with an18-announcement on our blog. We may obtain a CVE id as well. You may19-include a name and link if you would like to be credited for the report.modified:docs/conf.py+9 added-8 removed
9 unmodified lines10 release, version = get_version("Flask")11 12 # General --------------------------------------------------------------13 14-master_doc = "index"14+default_role = "code"15 extensions = [16 "sphinx.ext.autodoc",17+ "sphinx.ext.extlinks",18 "sphinx.ext.intersphinx",19 "sphinxcontrib.log_cabinet",19- "pallets_sphinx_themes",20- "sphinx_issues",20 "sphinx_tabs.tabs",21+ "pallets_sphinx_themes",22 ]23+autodoc_member_order = "bysource"24 autodoc_typehints = "description"25+autodoc_preserve_defaults = True26+extlinks = {27+ "issue": ("https://github.com/pallets/flask/issues/%s", "#%s"),28+ "pr": ("https://github.com/pallets/flask/pull/%s", "#%s"),29+}30 intersphinx_mapping = {31 "python": ("https://docs.python.org/3/", None),32 "werkzeug": ("https://werkzeug.palletsprojects.com/", None),33 "click": ("https://click.palletsprojects.com/", None),2 unmodified lines36 "sqlalchemy": ("https://docs.sqlalchemy.org/", None),37 "wtforms": ("https://wtforms.readthedocs.io/", None),38 "blinker": ("https://blinker.readthedocs.io/", None),39 }34-issues_github_path = "pallets/flask"40 41 # HTML -----------------------------------------------------------------42 43 html_theme = "flask"17 unmodified lines61 html_logo = "_static/flask-vertical.png"62 html_title = f"Flask Documentation ({version})"63 html_show_sourcelink = False64 60-# LaTeX ----------------------------------------------------------------61-62-latex_documents = [(master_doc, f"Flask-{version}.tex", html_title, author, "manual")]63-65 # Local Extensions -----------------------------------------------------66 67 68 def github_link(name, rawtext, text, lineno, inliner, options=None, content=None):29 unmodified linesmodified:docs/index.rst+1 added-1 removed
56 unmodified lines57 cli58 server59 shell60 patterns/index61- security61+ web-security62 deploying/index63 async-await64 65 23 unmodified linesmodified:docs/license.rst+2 added-1 removed
1 BSD-3-Clause License2 ====================3 4-.. include:: ../LICENSE.rst4+.. literalinclude:: ../LICENSE.txt5+ :language: textdeleted:docs/security.rst-274 removed
1-Security Considerations2-=======================3-4-Web applications usually face all kinds of security problems and it's very5-hard to get everything right. Flask tries to solve a few of these things6-for you, but there are a couple more you have to take care of yourself.7-8-.. _security-xss:9-10-Cross-Site Scripting (XSS)11---------------------------12-13-Cross site scripting is the concept of injecting arbitrary HTML (and with14-it JavaScript) into the context of a website. To remedy this, developers15-have to properly escape text so that it cannot include arbitrary HTML16-tags. For more information on that have a look at the Wikipedia article17-on `Cross-Site Scripting18-<https://en.wikipedia.org/wiki/Cross-site_scripting>`_.19-20-Flask configures Jinja2 to automatically escape all values unless21-explicitly told otherwise. This should rule out all XSS problems caused22-in templates, but there are still other places where you have to be23-careful:24-25-- generating HTML without the help of Jinja226-- calling :class:`~markupsafe.Markup` on data submitted by users27-- sending out HTML from uploaded files, never do that, use the28- ``Content-Disposition: attachment`` header to prevent that problem.29-- sending out textfiles from uploaded files. Some browsers are using30- content-type guessing based on the first few bytes so users could31- trick a browser to execute HTML.32-33-Another thing that is very important are unquoted attributes. While34-Jinja2 can protect you from XSS issues by escaping HTML, there is one35-thing it cannot protect you from: XSS by attribute injection. To counter36-this possible attack vector, be sure to always quote your attributes with37-either double or single quotes when using Jinja expressions in them:38-39-.. sourcecode:: html+jinja40-41- <input value="{{ value }}">42-43-Why is this necessary? Because if you would not be doing that, an44-attacker could easily inject custom JavaScript handlers. For example an45-attacker could inject this piece of HTML+JavaScript:46-47-.. sourcecode:: html48-49- onmouseover=alert(document.cookie)50-51-When the user would then move with the mouse over the input, the cookie52-would be presented to the user in an alert window. But instead of showing53-the cookie to the user, a good attacker might also execute any other54-JavaScript code. In combination with CSS injections the attacker might55-even make the element fill out the entire page so that the user would56-just have to have the mouse anywhere on the page to trigger the attack.57-58-There is one class of XSS issues that Jinja's escaping does not protect59-against. The ``a`` tag's ``href`` attribute can contain a `javascript:` URI,60-which the browser will execute when clicked if not secured properly.61-62-.. sourcecode:: html63-64- <a href="{{ value }}">click here</a>65- <a href="javascript:alert('unsafe');">click here</a>66-67-To prevent this, you'll need to set the :ref:`security-csp` response header.68-69-Cross-Site Request Forgery (CSRF)70----------------------------------71-72-Another big problem is CSRF. This is a very complex topic and I won't73-outline it here in detail just mention what it is and how to theoretically74-prevent it.75-76-If your authentication information is stored in cookies, you have implicit77-state management. The state of "being logged in" is controlled by a78-cookie, and that cookie is sent with each request to a page.79-Unfortunately that includes requests triggered by 3rd party sites. If you80-don't keep that in mind, some people might be able to trick your81-application's users with social engineering to do stupid things without82-them knowing.83-84-Say you have a specific URL that, when you sent ``POST`` requests to will85-delete a user's profile (say ``http://example.com/user/delete``). If an86-attacker now creates a page that sends a post request to that page with87-some JavaScript they just have to trick some users to load that page and88-their profiles will end up being deleted.89-90-Imagine you were to run Facebook with millions of concurrent users and91-someone would send out links to images of little kittens. When users92-would go to that page, their profiles would get deleted while they are93-looking at images of fluffy cats.94-95-How can you prevent that? Basically for each request that modifies96-content on the server you would have to either use a one-time token and97-store that in the cookie **and** also transmit it with the form data.98-After receiving the data on the server again, you would then have to99-compare the two tokens and ensure they are equal.100-101-Why does Flask not do that for you? The ideal place for this to happen is102-the form validation framework, which does not exist in Flask.103-104-.. _security-json:105-106-JSON Security107--------------108-109-In Flask 0.10 and lower, :func:`~flask.jsonify` did not serialize top-level110-arrays to JSON. This was because of a security vulnerability in ECMAScript 4.111-112-ECMAScript 5 closed this vulnerability, so only extremely old browsers are113-still vulnerable. All of these browsers have `other more serious114-vulnerabilities115-<https://github.com/pallets/flask/issues/248#issuecomment-59934857>`_, so116-this behavior was changed and :func:`~flask.jsonify` now supports serializing117-arrays.118-119-Security Headers120-----------------121-122-Browsers recognize various response headers in order to control security. We123-recommend reviewing each of the headers below for use in your application.124-The `Flask-Talisman`_ extension can be used to manage HTTPS and the security125-headers for you.126-127-.. _Flask-Talisman: https://github.com/GoogleCloudPlatform/flask-talisman128-129-HTTP Strict Transport Security (HSTS)130-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~131-132-Tells the browser to convert all HTTP requests to HTTPS, preventing133-man-in-the-middle (MITM) attacks. ::134-135- response.headers['Strict-Transport-Security'] = 'max-age=31536000; includeSubDomains'136-137-- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security138-139-.. _security-csp:140-141-Content Security Policy (CSP)142-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~143-144-Tell the browser where it can load various types of resource from. This header145-should be used whenever possible, but requires some work to define the correct146-policy for your site. A very strict policy would be::147-148- response.headers['Content-Security-Policy'] = "default-src 'self'"149-150-- https://csp.withgoogle.com/docs/index.html151-- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy152-153-X-Content-Type-Options154-~~~~~~~~~~~~~~~~~~~~~~155-156-Forces the browser to honor the response content type instead of trying to157-detect it, which can be abused to generate a cross-site scripting (XSS)158-attack. ::159-160- response.headers['X-Content-Type-Options'] = 'nosniff'161-162-- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options163-164-X-Frame-Options165-~~~~~~~~~~~~~~~166-167-Prevents external sites from embedding your site in an ``iframe``. This168-prevents a class of attacks where clicks in the outer frame can be translated169-invisibly to clicks on your page's elements. This is also known as170-"clickjacking". ::171-172- response.headers['X-Frame-Options'] = 'SAMEORIGIN'173-174-- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options175-176-.. _security-cookie:177-178-Set-Cookie options179-~~~~~~~~~~~~~~~~~~180-181-These options can be added to a ``Set-Cookie`` header to improve their182-security. Flask has configuration options to set these on the session cookie.183-They can be set on other cookies too.184-185-- ``Secure`` limits cookies to HTTPS traffic only.186-- ``HttpOnly`` protects the contents of cookies from being read with187- JavaScript.188-- ``SameSite`` restricts how cookies are sent with requests from189- external sites. Can be set to ``'Lax'`` (recommended) or ``'Strict'``.190- ``Lax`` prevents sending cookies with CSRF-prone requests from191- external sites, such as submitting a form. ``Strict`` prevents sending192- cookies with all external requests, including following regular links.193-194-::195-196- app.config.update(197- SESSION_COOKIE_SECURE=True,198- SESSION_COOKIE_HTTPONLY=True,199- SESSION_COOKIE_SAMESITE='Lax',200- )201-202- response.set_cookie('username', 'flask', secure=True, httponly=True, samesite='Lax')203-204-Specifying ``Expires`` or ``Max-Age`` options, will remove the cookie after205-the given time, or the current time plus the age, respectively. If neither206-option is set, the cookie will be removed when the browser is closed. ::207-208- # cookie expires after 10 minutes209- response.set_cookie('snakes', '3', max_age=600)210-211-For the session cookie, if :attr:`session.permanent <flask.session.permanent>`212-is set, then :data:`PERMANENT_SESSION_LIFETIME` is used to set the expiration.213-Flask's default cookie implementation validates that the cryptographic214-signature is not older than this value. Lowering this value may help mitigate215-replay attacks, where intercepted cookies can be sent at a later time. ::216-217- app.config.update(218- PERMANENT_SESSION_LIFETIME=600219- )220-221- @app.route('/login', methods=['POST'])222- def login():223- ...224- session.clear()225- session['user_id'] = user.id226- session.permanent = True227- ...228-229-Use :class:`itsdangerous.TimedSerializer` to sign and validate other cookie230-values (or any values that need secure signatures).231-232-- https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies233-- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie234-235-.. _samesite_support: https://caniuse.com/#feat=same-site-cookie-attribute236-237-238-HTTP Public Key Pinning (HPKP)239-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~240-241-This tells the browser to authenticate with the server using only the specific242-certificate key to prevent MITM attacks.243-244-.. warning::245- Be careful when enabling this, as it is very difficult to undo if you set up246- or upgrade your key incorrectly.247-248-- https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning249-250-251-Copy/Paste to Terminal252-----------------------253-254-Hidden characters such as the backspace character (``\b``, ``^H``) can255-cause text to render differently in HTML than how it is interpreted if256-`pasted into a terminal <https://security.stackexchange.com/q/39118>`__.257-258-For example, ``import y\bose\bm\bi\bt\be\b`` renders as259-``import yosemite`` in HTML, but the backspaces are applied when pasted260-into a terminal, and it becomes ``import os``.261-262-If you expect users to copy and paste untrusted code from your site,263-such as from comments posted by users on a technical blog, consider264-applying extra filtering, such as replacing all ``\b`` characters.265-266-.. code-block:: python267-268- body = body.replace("\b", "")269-270-Most modern terminals will warn about and remove hidden characters when271-pasting, so this isn't strictly necessary. It's also possible to craft272-dangerous commands in other ways that aren't possible to filter.273-Depending on your site's use case, it may be good to show a warning274-about copying code in general.added:docs/web-security.rst+274 added
1+Security Considerations2+=======================3+4+Web applications usually face all kinds of security problems and it's very5+hard to get everything right. Flask tries to solve a few of these things6+for you, but there are a couple more you have to take care of yourself.7+8+.. _security-xss:9+10+Cross-Site Scripting (XSS)11+--------------------------12+13+Cross site scripting is the concept of injecting arbitrary HTML (and with14+it JavaScript) into the context of a website. To remedy this, developers15+have to properly escape text so that it cannot include arbitrary HTML16+tags. For more information on that have a look at the Wikipedia article17+on `Cross-Site Scripting18+<https://en.wikipedia.org/wiki/Cross-site_scripting>`_.19+20+Flask configures Jinja2 to automatically escape all values unless21+explicitly told otherwise. This should rule out all XSS problems caused22+in templates, but there are still other places where you have to be23+careful:24+25+- generating HTML without the help of Jinja226+- calling :class:`~markupsafe.Markup` on data submitted by users27+- sending out HTML from uploaded files, never do that, use the28+ ``Content-Disposition: attachment`` header to prevent that problem.29+- sending out textfiles from uploaded files. Some browsers are using30+ content-type guessing based on the first few bytes so users could31+ trick a browser to execute HTML.32+33+Another thing that is very important are unquoted attributes. While34+Jinja2 can protect you from XSS issues by escaping HTML, there is one35+thing it cannot protect you from: XSS by attribute injection. To counter36+this possible attack vector, be sure to always quote your attributes with37+either double or single quotes when using Jinja expressions in them:38+39+.. sourcecode:: html+jinja40+41+ <input value="{{ value }}">42+43+Why is this necessary? Because if you would not be doing that, an44+attacker could easily inject custom JavaScript handlers. For example an45+attacker could inject this piece of HTML+JavaScript:46+47+.. sourcecode:: html48+49+ onmouseover=alert(document.cookie)50+51+When the user would then move with the mouse over the input, the cookie52+would be presented to the user in an alert window. But instead of showing53+the cookie to the user, a good attacker might also execute any other54+JavaScript code. In combination with CSS injections the attacker might55+even make the element fill out the entire page so that the user would56+just have to have the mouse anywhere on the page to trigger the attack.57+58+There is one class of XSS issues that Jinja's escaping does not protect59+against. The ``a`` tag's ``href`` attribute can contain a `javascript:` URI,60+which the browser will execute when clicked if not secured properly.61+62+.. sourcecode:: html63+64+ <a href="{{ value }}">click here</a>65+ <a href="javascript:alert('unsafe');">click here</a>66+67+To prevent this, you'll need to set the :ref:`security-csp` response header.68+69+Cross-Site Request Forgery (CSRF)70+---------------------------------71+72+Another big problem is CSRF. This is a very complex topic and I won't73+outline it here in detail just mention what it is and how to theoretically74+prevent it.75+76+If your authentication information is stored in cookies, you have implicit77+state management. The state of "being logged in" is controlled by a78+cookie, and that cookie is sent with each request to a page.79+Unfortunately that includes requests triggered by 3rd party sites. If you80+don't keep that in mind, some people might be able to trick your81+application's users with social engineering to do stupid things without82+them knowing.83+84+Say you have a specific URL that, when you sent ``POST`` requests to will85+delete a user's profile (say ``http://example.com/user/delete``). If an86+attacker now creates a page that sends a post request to that page with87+some JavaScript they just have to trick some users to load that page and88+their profiles will end up being deleted.89+90+Imagine you were to run Facebook with millions of concurrent users and91+someone would send out links to images of little kittens. When users92+would go to that page, their profiles would get deleted while they are93+looking at images of fluffy cats.94+95+How can you prevent that? Basically for each request that modifies96+content on the server you would have to either use a one-time token and97+store that in the cookie **and** also transmit it with the form data.98+After receiving the data on the server again, you would then have to99+compare the two tokens and ensure they are equal.100+101+Why does Flask not do that for you? The ideal place for this to happen is102+the form validation framework, which does not exist in Flask.103+104+.. _security-json:105+106+JSON Security107+-------------108+109+In Flask 0.10 and lower, :func:`~flask.jsonify` did not serialize top-level110+arrays to JSON. This was because of a security vulnerability in ECMAScript 4.111+112+ECMAScript 5 closed this vulnerability, so only extremely old browsers are113+still vulnerable. All of these browsers have `other more serious114+vulnerabilities115+<https://github.com/pallets/flask/issues/248#issuecomment-59934857>`_, so116+this behavior was changed and :func:`~flask.jsonify` now supports serializing117+arrays.118+119+Security Headers120+----------------121+122+Browsers recognize various response headers in order to control security. We123+recommend reviewing each of the headers below for use in your application.124+The `Flask-Talisman`_ extension can be used to manage HTTPS and the security125+headers for you.126+127+.. _Flask-Talisman: https://github.com/GoogleCloudPlatform/flask-talisman128+129+HTTP Strict Transport Security (HSTS)130+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~131+132+Tells the browser to convert all HTTP requests to HTTPS, preventing133+man-in-the-middle (MITM) attacks. ::134+135+ response.headers['Strict-Transport-Security'] = 'max-age=31536000; includeSubDomains'136+137+- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security138+139+.. _security-csp:140+141+Content Security Policy (CSP)142+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~143+144+Tell the browser where it can load various types of resource from. This header145+should be used whenever possible, but requires some work to define the correct146+policy for your site. A very strict policy would be::147+148+ response.headers['Content-Security-Policy'] = "default-src 'self'"149+150+- https://csp.withgoogle.com/docs/index.html151+- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy152+153+X-Content-Type-Options154+~~~~~~~~~~~~~~~~~~~~~~155+156+Forces the browser to honor the response content type instead of trying to157+detect it, which can be abused to generate a cross-site scripting (XSS)158+attack. ::159+160+ response.headers['X-Content-Type-Options'] = 'nosniff'161+162+- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options163+164+X-Frame-Options165+~~~~~~~~~~~~~~~166+167+Prevents external sites from embedding your site in an ``iframe``. This168+prevents a class of attacks where clicks in the outer frame can be translated169+invisibly to clicks on your page's elements. This is also known as170+"clickjacking". ::171+172+ response.headers['X-Frame-Options'] = 'SAMEORIGIN'173+174+- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options175+176+.. _security-cookie:177+178+Set-Cookie options179+~~~~~~~~~~~~~~~~~~180+181+These options can be added to a ``Set-Cookie`` header to improve their182+security. Flask has configuration options to set these on the session cookie.183+They can be set on other cookies too.184+185+- ``Secure`` limits cookies to HTTPS traffic only.186+- ``HttpOnly`` protects the contents of cookies from being read with187+ JavaScript.188+- ``SameSite`` restricts how cookies are sent with requests from189+ external sites. Can be set to ``'Lax'`` (recommended) or ``'Strict'``.190+ ``Lax`` prevents sending cookies with CSRF-prone requests from191+ external sites, such as submitting a form. ``Strict`` prevents sending192+ cookies with all external requests, including following regular links.193+194+::195+196+ app.config.update(197+ SESSION_COOKIE_SECURE=True,198+ SESSION_COOKIE_HTTPONLY=True,199+ SESSION_COOKIE_SAMESITE='Lax',200+ )201+202+ response.set_cookie('username', 'flask', secure=True, httponly=True, samesite='Lax')203+204+Specifying ``Expires`` or ``Max-Age`` options, will remove the cookie after205+the given time, or the current time plus the age, respectively. If neither206+option is set, the cookie will be removed when the browser is closed. ::207+208+ # cookie expires after 10 minutes209+ response.set_cookie('snakes', '3', max_age=600)210+211+For the session cookie, if :attr:`session.permanent <flask.session.permanent>`212+is set, then :data:`PERMANENT_SESSION_LIFETIME` is used to set the expiration.213+Flask's default cookie implementation validates that the cryptographic214+signature is not older than this value. Lowering this value may help mitigate215+replay attacks, where intercepted cookies can be sent at a later time. ::216+217+ app.config.update(218+ PERMANENT_SESSION_LIFETIME=600219+ )220+221+ @app.route('/login', methods=['POST'])222+ def login():223+ ...224+ session.clear()225+ session['user_id'] = user.id226+ session.permanent = True227+ ...228+229+Use :class:`itsdangerous.TimedSerializer` to sign and validate other cookie230+values (or any values that need secure signatures).231+232+- https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies233+- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie234+235+.. _samesite_support: https://caniuse.com/#feat=same-site-cookie-attribute236+237+238+HTTP Public Key Pinning (HPKP)239+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~240+241+This tells the browser to authenticate with the server using only the specific242+certificate key to prevent MITM attacks.243+244+.. warning::245+ Be careful when enabling this, as it is very difficult to undo if you set up246+ or upgrade your key incorrectly.247+248+- https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning249+250+251+Copy/Paste to Terminal252+----------------------253+254+Hidden characters such as the backspace character (``\b``, ``^H``) can255+cause text to render differently in HTML than how it is interpreted if256+`pasted into a terminal <https://security.stackexchange.com/q/39118>`__.257+258+For example, ``import y\bose\bm\bi\bt\be\b`` renders as259+``import yosemite`` in HTML, but the backspaces are applied when pasted260+into a terminal, and it becomes ``import os``.261+262+If you expect users to copy and paste untrusted code from your site,263+such as from comments posted by users on a technical blog, consider264+applying extra filtering, such as replacing all ``\b`` characters.265+266+.. code-block:: python267+268+ body = body.replace("\b", "")269+270+Most modern terminals will warn about and remove hidden characters when271+pasting, so this isn't strictly necessary. It's also possible to craft272+dangerous commands in other ways that aren't possible to filter.273+Depending on your site's use case, it may be good to show a warning274+about copying code in general.modified:requirements/build.txt+3 added-3 removed
1 #2-# This file is autogenerated by pip-compile with Python 3.112+# This file is autogenerated by pip-compile with Python 3.123 # by the following command:4 #5 # pip-compile build.in6 #7-build==1.0.37+build==1.2.18 # via -r build.in9-packaging==23.29+packaging==24.010 # via build11 pyproject-hooks==1.0.012 # via buildmodified:requirements/dev.in+3 added-4 removed
1--r docs.in2--r tests.in3--r typing.in4-pip-tools1+-r docs.txt2+-r tests.txt3+-r typing.txt4 pre-commit5 toxmodified:requirements/dev.txt+115 added-71 removed
1 #2-# This file is autogenerated by pip-compile with Python 3.112+# This file is autogenerated by pip-compile with Python 3.123 # by the following command:4 #5 # pip-compile dev.in6 #7 alabaster==0.7.168- # via sphinx9-asgiref==3.7.28 # via9+ # -r docs.txt10+ # sphinx11+asgiref==3.8.112+ # via11- # -r tests.in12- # -r typing.in13+ # -r tests.txt14+ # -r typing.txt15 babel==2.14.014- # via sphinx15-build==1.0.316- # via pip-tools17-cachetools==5.3.216+ # via17+ # -r docs.txt18+ # sphinx19+cachetools==5.3.320 # via tox19-certifi==2023.11.1720- # via requests21+certifi==2024.2.222+ # via23+ # -r docs.txt24+ # requests25 cffi==1.16.026+ # via27+ # -r typing.txt22- # via cryptography28+ # cryptography29 cfgv==3.4.030 # via pre-commit31 chardet==5.2.032 # via tox33 charset-normalizer==3.3.228- # via requests29-click==8.1.730- # via pip-tools34+ # via35+ # -r docs.txt36+ # requests37 colorama==0.4.638 # via tox33-cryptography==42.0.234- # via -r typing.in39+cryptography==42.0.540+ # via -r typing.txt41 distlib==0.3.842 # via virtualenv37-docutils==0.18.143+docutils==0.20.144 # via45+ # -r docs.txt46 # sphinx47 # sphinx-tabs41-filelock==3.13.148+filelock==3.13.349 # via50 # tox51 # virtualenv45-identify==2.5.3352+identify==2.5.3553 # via pre-commit54 idna==3.648- # via requests55+ # via56+ # -r docs.txt57+ # requests58 imagesize==1.4.150- # via sphinx59+ # via60+ # -r docs.txt61+ # sphinx62 iniconfig==2.0.052- # via pytest63+ # via64+ # -r tests.txt65+ # -r typing.txt66+ # pytest67 jinja2==3.1.354- # via sphinx55-markupsafe==2.1.356- # via jinja257-mypy==1.8.058- # via -r typing.in68+ # via69+ # -r docs.txt70+ # sphinx71+markupsafe==2.1.572+ # via73+ # -r docs.txt74+ # jinja275+mypy==1.9.076+ # via -r typing.txt77 mypy-extensions==1.0.060- # via mypy78+ # via79+ # -r typing.txt80+ # mypy81 nodeenv==1.8.062- # via pre-commit63-packaging==23.282 # via65- # build83+ # -r typing.txt84+ # pre-commit85+ # pyright86+packaging==24.087+ # via88+ # -r docs.txt89+ # -r tests.txt90+ # -r typing.txt91 # pallets-sphinx-themes92 # pyproject-api93 # pytest94 # sphinx95 # tox96 pallets-sphinx-themes==2.1.172- # via -r docs.in73-pip-tools==7.3.074- # via -r dev.in75-platformdirs==4.1.097+ # via -r docs.txt98+platformdirs==4.2.099 # via100 # tox101 # virtualenv79-pluggy==1.3.0102+pluggy==1.4.0103 # via104+ # -r tests.txt105+ # -r typing.txt106 # pytest107 # tox83-pre-commit==3.6.0108+pre-commit==3.7.0109 # via -r dev.in85-pycparser==2.2186- # via cffi110+pycparser==2.22111+ # via112+ # -r typing.txt113+ # cffi114 pygments==2.17.2115 # via116+ # -r docs.txt117 # sphinx118 # sphinx-tabs119 pyproject-api==1.6.1120 # via tox93-pyproject-hooks==1.0.094- # via build95-pytest==8.0.096- # via -r tests.in121+pyright==1.1.357122+ # via -r typing.txt123+pytest==8.1.1124+ # via125+ # -r tests.txt126+ # -r typing.txt127 python-dotenv==1.0.1128 # via99- # -r tests.in100- # -r typing.in129+ # -r tests.txt130+ # -r typing.txt131 pyyaml==6.0.1132 # via pre-commit133 requests==2.31.0104- # via sphinx134+ # via135+ # -r docs.txt136+ # sphinx137 snowballstemmer==2.2.0106- # via sphinx138+ # via139+ # -r docs.txt140+ # sphinx141 sphinx==7.2.6142 # via109- # -r docs.in143+ # -r docs.txt144 # pallets-sphinx-themes111- # sphinx-issues145 # sphinx-tabs146 # sphinxcontrib-log-cabinet114-sphinx-issues==4.0.0115- # via -r docs.in147 sphinx-tabs==3.4.5117- # via -r docs.in148+ # via -r docs.txt149 sphinxcontrib-applehelp==1.0.8119- # via sphinx150+ # via151+ # -r docs.txt152+ # sphinx153 sphinxcontrib-devhelp==1.0.6121- # via sphinx154+ # via155+ # -r docs.txt156+ # sphinx157 sphinxcontrib-htmlhelp==2.0.5123- # via sphinx158+ # via159+ # -r docs.txt160+ # sphinx161 sphinxcontrib-jsmath==1.0.1125- # via sphinx162+ # via163+ # -r docs.txt164+ # sphinx165 sphinxcontrib-log-cabinet==1.0.1127- # via -r docs.in166+ # via -r docs.txt167 sphinxcontrib-qthelp==1.0.7129- # via sphinx168+ # via169+ # -r docs.txt170+ # sphinx171 sphinxcontrib-serializinghtml==1.1.10172+ # via173+ # -r docs.txt131- # via sphinx132-tox==4.12.1174+ # sphinx175+tox==4.14.2176 # via -r dev.in177 types-contextvars==2.4.7.3135- # via -r typing.in178+ # via -r typing.txt179 types-dataclasses==0.6.6137- # via -r typing.in138-typing-extensions==4.9.0139- # via mypy140-urllib3==2.1.0141- # via requests142-virtualenv==20.25.0180+ # via -r typing.txt181+typing-extensions==4.11.0182 # via183+ # -r typing.txt184+ # mypy185+urllib3==2.2.1186+ # via187+ # -r docs.txt188+ # requests189+virtualenv==20.25.1190+ # via191 # pre-commit192 # tox146-wheel==0.42.0147- # via pip-tools193 194 # The following packages are considered to be unsafe in a requirements file:150-# pip195 # setuptoolsmodified:requirements/docs.in-1 removed
1 pallets-sphinx-themes2 sphinx3-sphinx-issues3 sphinxcontrib-log-cabinet4 sphinx-tabsmodified:requirements/docs.txt+6 added-9 removed
1 #2-# This file is autogenerated by pip-compile with Python 3.112+# This file is autogenerated by pip-compile with Python 3.123 # by the following command:4 #5 # pip-compile docs.in6 #7 alabaster==0.7.168 # via sphinx9 babel==2.14.010 # via sphinx11-certifi==2023.11.1711+certifi==2024.2.212 # via requests13 charset-normalizer==3.3.214 # via requests15-docutils==0.18.115+docutils==0.20.116 # via17 # sphinx18 # sphinx-tabs19 idna==3.61 unmodified line21 imagesize==1.4.122 # via sphinx23 jinja2==3.1.324 # via sphinx25-markupsafe==2.1.325+markupsafe==2.1.526 # via jinja227-packaging==23.227+packaging==24.028 # via29 # pallets-sphinx-themes30 # sphinx31 pallets-sphinx-themes==2.1.19 unmodified lines41 sphinx==7.2.642 # via43 # -r docs.in44 # pallets-sphinx-themes45- # sphinx-issues45 # sphinx-tabs46 # sphinxcontrib-log-cabinet48-sphinx-issues==4.0.049- # via -r docs.in47 sphinx-tabs==3.4.548 # via -r docs.in49 sphinxcontrib-applehelp==1.0.850 # via sphinx8 unmodified lines59 sphinxcontrib-qthelp==1.0.760 # via sphinx61 sphinxcontrib-serializinghtml==1.1.1062 # via sphinx66-urllib3==2.1.063+urllib3==2.2.164 # via requestsmodified:requirements/tests.txt+5 added-5 removed
1 #2-# This file is autogenerated by pip-compile with Python 3.112+# This file is autogenerated by pip-compile with Python 3.123 # by the following command:4 #5 # pip-compile tests.in6 #7-asgiref==3.7.27+asgiref==3.8.18 # via -r tests.in9 iniconfig==2.0.010 # via pytest11-packaging==23.211+packaging==24.012 # via pytest13-pluggy==1.3.013+pluggy==1.4.014 # via pytest15-pytest==8.0.015+pytest==8.1.116 # via -r tests.in17 python-dotenv==1.0.118 # via -r tests.inmodified:requirements/typing.in+2 added
1 mypy2+pyright3+pytest4 types-contextvars5 types-dataclasses6 asgiref7 cryptography1 unmodified linemodified:requirements/typing.txt+21 added-6 removed
1 #2-# This file is autogenerated by pip-compile with Python 3.112+# This file is autogenerated by pip-compile with Python 3.123 # by the following command:4 #5 # pip-compile typing.in6 #7-asgiref==3.7.27+asgiref==3.8.18 # via -r typing.in9 cffi==1.16.010 # via cryptography11-cryptography==42.0.211+cryptography==42.0.512 # via -r typing.in13+iniconfig==2.0.014+ # via pytest13-mypy==1.8.015+mypy==1.9.016 # via -r typing.in17 mypy-extensions==1.0.018 # via mypy19+nodeenv==1.8.020+ # via pyright21+packaging==24.022+ # via pytest23+pluggy==1.4.024+ # via pytest17-pycparser==2.2125+pycparser==2.2226 # via cffi27+pyright==1.1.35728+ # via -r typing.in29+pytest==8.1.130+ # via -r typing.in31 python-dotenv==1.0.132 # via -r typing.in33 types-contextvars==2.4.7.334 # via -r typing.in35 types-dataclasses==0.6.636 # via -r typing.in25-typing-extensions==4.9.037+typing-extensions==4.11.038 # via mypy39+40+# The following packages are considered to be unsafe in a requirements file:41+# setuptoolsmodified:src/flask/json/tag.py+1 added
38 unmodified lines39 return OrderedDict(value)40 41 app.session_interface.serializer.register(TagOrderedDict, index=0)42 """43+44 from __future__ import annotations45 46 import typing as t47 from base64 import b64decode280 unmodified linesmodified:src/flask/cli.py+2 added-4 removed
227 unmodified lines228 229 @t.overload230 def locate_app(231 module_name: str, app_name: str | None, raise_if_not_found: t.Literal[True] = True232-) -> Flask:233- ...232+) -> Flask: ...233 234 235 @t.overload236 def locate_app(237 module_name: str, app_name: str | None, raise_if_not_found: t.Literal[False] = ...239-) -> Flask | None:240- ...238+) -> Flask | None: ...239 240 241 def locate_app(242 module_name: str, app_name: str | None, raise_if_not_found: bool = True867 unmodified linesmodified:src/flask/config.py+2 added-4 removed
25 unmodified lines26 self.__name__ = name27 self.get_converter = get_converter28 29 @t.overload30- def __get__(self, obj: None, owner: None) -> te.Self:31- ...30+ def __get__(self, obj: None, owner: None) -> te.Self: ...31 32 @t.overload34- def __get__(self, obj: App, owner: type[App]) -> T:35- ...33+ def __get__(self, obj: App, owner: type[App]) -> T: ...34 35 def __get__(self, obj: App | None, owner: type[App] | None = None) -> T | te.Self:36 if obj is None:37 return self333 unmodified linesmodified:tests/typing/typing_app_decorators.py+4 added-8 removed
15 unmodified lines16 return Response()17 18 19 @app.before_request20-def before_sync() -> None:21- ...20+def before_sync() -> None: ...21 22 23 @app.before_request25-async def before_async() -> None:26- ...24+async def before_async() -> None: ...25 26 27 @app.teardown_appcontext30-def teardown_sync(exc: BaseException | None) -> None:31- ...28+def teardown_sync(exc: BaseException | None) -> None: ...29 30 31 @app.teardown_appcontext35-async def teardown_async(exc: BaseException | None) -> None:36- ...32+async def teardown_async(exc: BaseException | None) -> None: ...modified:tests/test_json.py+1 added-1 removed
174 unmodified lines175 176 def test_jsonify_uuid_types(app, client):177 """Test jsonify with uuid.UUID types"""178 179- test_uuid = uuid.UUID(bytes=b"\xDE\xAD\xBE\xEF" * 4)179+ test_uuid = uuid.UUID(bytes=b"\xde\xad\xbe\xef" * 4)180 url = "/uuid_test"181 app.add_url_rule(url, url, lambda: flask.jsonify(x=test_uuid))182 183 rv = client.get(url)163 unmodified linesmodified:.editorconfig+1 added-1 removed
7 unmodified lines8 end_of_line = lf9 charset = utf-810 max_line_length = 8811 12-[*.{yml,yaml,json,js,css,html}]12+[*.{css,html,js,json,jsx,scss,ts,tsx,yaml,yml}]13 indent_size = 2modified:.gitignore+5 added-5 removed
1 .idea/2 .vscode/3+.venv*/4+venv*/5 __pycache__/4-.tox/5-.coverage6-.coverage.*6+dist/7+.coverage*8 htmlcov/9+.tox/10 docs/_build/9-dist/10-venv/modified:.pre-commit-config.yaml+2 added-2 removed
1 ci:2 autoupdate_schedule: monthly3 repos:4 - repo: https://github.com/astral-sh/ruff-pre-commit5- rev: v0.2.05+ rev: v0.3.56 hooks:7 - id: ruff8 - id: ruff-format9 - repo: https://github.com/pre-commit/pre-commit-hooks10- rev: v4.5.010+ rev: v4.6.011 hooks:12 - id: check-merge-conflict13 - id: debug-statements14 - id: fix-byte-order-marker2 unmodified linesmodified:.readthedocs.yaml+1 added-1 removed
1 version: 22 build:3 os: ubuntu-22.044 tools:5- python: "3.12"5+ python: '3.12'6 python:7 install:8 - requirements: requirements/docs.txt9 - method: pip4 unmodified linesdeleted:LICENSE.rst-28 removed
1-Copyright 2010 Pallets2-3-Redistribution and use in source and binary forms, with or without4-modification, are permitted provided that the following conditions are5-met:6-7-1. Redistributions of source code must retain the above copyright8- notice, this list of conditions and the following disclaimer.9-10-2. Redistributions in binary form must reproduce the above copyright11- notice, this list of conditions and the following disclaimer in the12- documentation and/or other materials provided with the distribution.13-14-3. Neither the name of the copyright holder nor the names of its15- contributors may be used to endorse or promote products derived from16- this software without specific prior written permission.17-18-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A21-PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT22-HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,23-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED24-TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR25-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF26-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING27-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS28-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.added:LICENSE.txt+28 added
1+Copyright 2010 Pallets2+3+Redistribution and use in source and binary forms, with or without4+modification, are permitted provided that the following conditions are5+met:6+7+1. Redistributions of source code must retain the above copyright8+ notice, this list of conditions and the following disclaimer.9+10+2. Redistributions in binary form must reproduce the above copyright11+ notice, this list of conditions and the following disclaimer in the12+ documentation and/or other materials provided with the distribution.13+14+3. Neither the name of the copyright holder nor the names of its15+ contributors may be used to endorse or promote products derived from16+ this software without specific prior written permission.17+18+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A21+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT22+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,23+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED24+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR25+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF26+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING27+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS28+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.modified:pyproject.toml+10 added-5 removed
1 [project]2 name = "Flask"3 version = "3.0.2"4 description = "A simple framework for building complex web applications."5-readme = "README.rst"6-license = {file = "LICENSE.rst"}5+readme = "README.md"6+license = {file = "LICENSE.txt"}7 maintainers = [{name = "Pallets", email = "contact@palletsprojects.com"}]8 classifiers = [9 "Development Status :: 5 - Production/Stable",10 "Environment :: Web Environment",5 unmodified lines16 "Topic :: Internet :: WWW/HTTP :: Dynamic Content",17 "Topic :: Internet :: WWW/HTTP :: WSGI",18 "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",19 "Topic :: Software Development :: Libraries :: Application Frameworks",20+ "Typing :: Typed",21 ]22 requires-python = ">=3.8"23 dependencies = [24 "Werkzeug>=3.0.0",7 unmodified lines32 [project.urls]33 Donate = "https://palletsprojects.com/donate"34 Documentation = "https://flask.palletsprojects.com/"35 Changes = "https://flask.palletsprojects.com/changes/"35-"Source Code" = "https://github.com/pallets/flask/"36-"Issue Tracker" = "https://github.com/pallets/flask/issues/"36+Source = "https://github.com/pallets/flask/"37 Chat = "https://discord.gg/pallets"38 39 [project.optional-dependencies]40 async = ["asgiref>=3.2"]51 unmodified lines92 "importlib_metadata",93 ]94 ignore_missing_imports = true95 96+[tool.pyright]97+pythonVersion = "3.8"98+include = ["src/flask", "tests"]99+typeCheckingMode = "basic"100+101 [tool.ruff]102 src = ["src"]103 fix = true104 show-fixes = true100-show-source = true105+output-format = "full"106 107 [tool.ruff.lint]108 select = [109 "B", # flake8-bugbear11 unmodified linesadded:README.md+65 added
1+# Flask2+3+Flask is a lightweight [WSGI][] web application framework. It is designed4+to make getting started quick and easy, with the ability to scale up to5+complex applications. It began as a simple wrapper around [Werkzeug][]6+and [Jinja][], and has become one of the most popular Python web7+application frameworks.8+9+Flask offers suggestions, but doesn't enforce any dependencies or10+project layout. It is up to the developer to choose the tools and11+libraries they want to use. There are many extensions provided by the12+community that make adding new functionality easy.13+14+[WSGI]: https://wsgi.readthedocs.io/15+[Werkzeug]: https://werkzeug.palletsprojects.com/16+[Jinja]: https://jinja.palletsprojects.com/17+18+19+## Installing20+21+Install and update from [PyPI][] using an installer such as [pip][]:22+23+```24+$ pip install -U Flask25+```26+27+[PyPI]: https://pypi.org/project/Flask/28+[pip]: https://pip.pypa.io/en/stable/getting-started/29+30+31+## A Simple Example32+33+```python34+# save this as app.py35+from flask import Flask36+37+app = Flask(__name__)38+39+@app.route("/")40+def hello():41+ return "Hello, World!"42+```43+44+```45+$ flask run46+ * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)47+```48+49+50+## Contributing51+52+For guidance on setting up a development environment and how to make a53+contribution to Flask, see the [contributing guidelines][].54+55+[contributing guidelines]: https://github.com/pallets/flask/blob/main/CONTRIBUTING.rst56+57+58+## Donate59+60+The Pallets organization develops and supports Flask and the libraries61+it uses. In order to grow the community of contributors and users, and62+allow the maintainers to devote more time to the projects, [please63+donate today][].64+65+[please donate today]: https://palletsprojects.com/donatedeleted:README.rst-80 removed
1-Flask2-=====3-4-Flask is a lightweight `WSGI`_ web application framework. It is designed5-to make getting started quick and easy, with the ability to scale up to6-complex applications. It began as a simple wrapper around `Werkzeug`_7-and `Jinja`_ and has become one of the most popular Python web8-application frameworks.9-10-Flask offers suggestions, but doesn't enforce any dependencies or11-project layout. It is up to the developer to choose the tools and12-libraries they want to use. There are many extensions provided by the13-community that make adding new functionality easy.14-15-.. _WSGI: https://wsgi.readthedocs.io/16-.. _Werkzeug: https://werkzeug.palletsprojects.com/17-.. _Jinja: https://jinja.palletsprojects.com/18-19-20-Installing21-----------22-23-Install and update using `pip`_:24-25-.. code-block:: text26-27- $ pip install -U Flask28-29-.. _pip: https://pip.pypa.io/en/stable/getting-started/30-31-32-A Simple Example33-----------------34-35-.. code-block:: python36-37- # save this as app.py38- from flask import Flask39-40- app = Flask(__name__)41-42- @app.route("/")43- def hello():44- return "Hello, World!"45-46-.. code-block:: text47-48- $ flask run49- * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)50-51-52-Contributing53-------------54-55-For guidance on setting up a development environment and how to make a56-contribution to Flask, see the `contributing guidelines`_.57-58-.. _contributing guidelines: https://github.com/pallets/flask/blob/main/CONTRIBUTING.rst59-60-61-Donate62-------63-64-The Pallets organization develops and supports Flask and the libraries65-it uses. In order to grow the community of contributors and users, and66-allow the maintainers to devote more time to the projects, `please67-donate today`_.68-69-.. _please donate today: https://palletsprojects.com/donate70-71-72-Links73------74-75-- Documentation: https://flask.palletsprojects.com/76-- Changes: https://flask.palletsprojects.com/changes/77-- PyPI Releases: https://pypi.org/project/Flask/78-- Source Code: https://github.com/pallets/flask/79-- Issue Tracker: https://github.com/pallets/flask/issues/80-- Chat: https://discord.gg/palletsmodified:tox.ini+17 added-3 removed
1 [tox]2 envlist =3 py3{12,11,10,9,8}4 pypy3105- py311-min5+ py312-min6 py38-dev7 style8 typing9 docs8 unmodified lines18 deps =19 -r requirements/tests.txt20 min: -r requirements-skip/tests-min.txt21 dev: -r requirements-skip/tests-dev.txt22-commands = pytest -v --tb=short --basetemp={envtmpdir} {posargs:tests}22+commands = pytest -v --tb=short --basetemp={envtmpdir} {posargs}23 24 [testenv:style]25 deps = pre-commit26 skip_install = true4 unmodified lines31 commands = mypy32 33 [testenv:docs]34 deps = -r requirements/docs.txt35-commands = sphinx-build -W -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html35+commands = sphinx-build -W -b dirhtml docs docs/_build/dirhtml36+37+[testenv:update-requirements]38+deps =39+ pip-tools40+ pre-commit41+skip_install = true42+change_dir = requirements43+commands =44+ pre-commit autoupdate -j445+ pip-compile -U build.in46+ pip-compile -U docs.in47+ pip-compile -U tests.in48+ pip-compile -U typing.in49+ pip-compile -U dev.in