Skip to content
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

Set explicit Origin in CORS preflight response if allow_credentials is True and allow_origins is wildcard #1113

Merged
merged 9 commits into from Apr 14, 2021

Commits on Dec 11, 2020

  1. Set explicit Origin in CORS preflight response if allow_credentials i…

    …s True and allow_origins is wildcard
    
    When making a preflight request, the browser makes no indication as to whether the actual subsequent
    request will pass up credentials. However, unless the preflight response explicitly allows the
    request's `Origin` in the `Access-Control-Response-Header`, the browser will fail the CORS check and
    prevent the actual follow-up CORS request. This means that responding with the `*` wildcard is not
    sufficient to allow preflighted credentialed requests. The current workaround is to provide an
    equivalently permissive `allow_origin_regex` pattern.
    
    The `simple_response()` code already performs similar logic which currently only applies to
    non-preflighted requests since the browser would never make a preflighted request that hits this
    code due to this issue:
    
    ```
    if self.allow_all_origins and has_cookie:
        headers["Access-Control-Allow-Origin"] = origin
    ```
    
    This just bring the two halves inline with each other.
    Josh Wilson committed Dec 11, 2020
    Copy the full SHA
    e804fff View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    1a28cce View commit details
    Browse the repository at this point in the history

Commits on Apr 4, 2021

  1. Copy the full SHA
    78e3adf View commit details
    Browse the repository at this point in the history

Commits on Apr 7, 2021

  1. Copy the full SHA
    a6018d0 View commit details
    Browse the repository at this point in the history
  2. Use allow_explicit_origin() for preflight request_headers

    This simplifies the code slightly by using this recently added method.
    
    It has some trade-offs, though. We now construct a `MutableHeaders` instead of a simple `dict` when
    copying the pre-computed preflight headers, and we move the `Vary` header construction out of the
    pre-computation and into the call handler.
    
    I think it makes the code more maintainable and the added per-call computation is minimal.
    Josh Wilson committed Apr 7, 2021
    Copy the full SHA
    2ac9646 View commit details
    Browse the repository at this point in the history
  3. Convert MutableHeaders to dict for PlainTextResponse

    Josh Wilson committed Apr 7, 2021
    Copy the full SHA
    b100232 View commit details
    Browse the repository at this point in the history
  4. Revert back to dict() for preflight headers

    This also names and caches some of the boolean tests in __init__() which we use in later if-blocks.
    This follows the existing pattern in order to better self-document the code.
    Josh Wilson committed Apr 7, 2021
    Copy the full SHA
    496983c View commit details
    Browse the repository at this point in the history
  5. Clean up comments

    Josh Wilson committed Apr 7, 2021
    Copy the full SHA
    5ee63ac View commit details
    Browse the repository at this point in the history
  6. Remove unused self.allow_credentials attribute

    Josh Wilson committed Apr 7, 2021
    Copy the full SHA
    d15f3b0 View commit details
    Browse the repository at this point in the history