GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [security] CVE-2021-28861: http.server: Open Redirection if the URL path starts with // · Issue #87389 · python/cpython

[security] CVE-2021-28861: http.server: Open Redirection if the URL path starts with // #87389

New issue
Copy link
New issue
Copy link
Closed
Closed
[security] CVE-2021-28861: http.server: Open Redirection if the URL path starts with //#87389
Copy link
Assignees
gpshead
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifedeferred-blockerstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-securityA security issueA security issue

Description

hamzaavvan
mannequin
opened on Feb 14, 2021
Issue body actions
BPO 43223
Nosy @pfmoore, @vstinner, @tiran, @tjguk, @ned-deily, @ambv, @zware, @zooba, @hamzaavvan
PRs
  • bpo-43223: [SECURITY] Patched Open Redirection In SimpleHTTPServer Module #24848
  • Files
  • Capture.PNG
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2021-02-14.11:42:36.898>
    labels = ['type-security', 'deferred-blocker', '3.8', '3.9', '3.10', '3.11', '3.7', 'library']
    title = '[security] http.server: Open Redirection if the URL path starts with //'
    updated_at = <Date 2021-05-23.08:10:57.234>
    user = 'https://github.com/hamzaavvan'

    bugs.python.org fields:

    activity = <Date 2021-05-23.08:10:57.234>
    actor = 'hamzaavvan'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2021-02-14.11:42:36.898>
    creator = 'hamzaavvan'
    dependencies = []
    files = ['49808']
    hgrepos = ['404']
    issue_num = 43223
    keywords = ['patch']
    message_count = 5.0
    messages = ['386945', '387193', '387284', '390047', '394193']
    nosy_count = 9.0
    nosy_names = ['paul.moore', 'vstinner', 'christian.heimes', 'tim.golden', 'ned.deily', 'lukasz.langa', 'zach.ware', 'steve.dower', 'hamzaavvan']
    pr_nums = ['24848']
    priority = 'deferred blocker'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'security'
    url = 'https://bugs.python.org/issue43223'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10', 'Python 3.11']

    Linked PRs

    • gh-87389: avoid treating path as URI with netloc #93894

    Activity

    Next
    1. hamzaavvan commented on Feb 14, 2021

      @hamzaavvan
      hamzaavvanmannequin
      on Feb 14, 2021
      MannequinAuthor
      More actions

      The provided version of python distros 3.8.7 and 3.7.4 are vulnerable to open redirection while traversing to an existing directory.

      # PAYLOAD
      http://127.0.0.1:8000//attacker.com/..%2f..%2f..%2f..%2f..%2f../%0a%0d/../.ssh

      In this case, the actual path of .ssh was:
      http://127.0.0.1:8000/.ssh

      Upon visiting the payload URI the python server will respond back with a Location header instead of serving the directory contents directly which triggers the redirection to attacker.com

      Server: SimpleHTTP/0.6 Python/3.8.7

    2. hamzaavvan
      added
      OS-windows
      type-securityA security issueA security issue
      3.7 (EOL)end of lifeend of life
      3.8 (EOL)end of lifeend of life
      on Feb 14, 2021
    3. hamzaavvan
      changed the title [-]Open Redirection In Python 3.7 & 3.8[/-] [+][SECURITY] Open Redirection In Python 3.7 & 3.8[/+] on Feb 15, 2021
    4. hamzaavvan
      changed the title [-]Open Redirection In Python 3.7 & 3.8[/-] [+][SECURITY] Open Redirection In Python 3.7 & 3.8[/+] on Feb 15, 2021
    5. vstinner commented on Feb 17, 2021

      @vstinner
      vstinner
      on Feb 17, 2021
      Member
      More actions

      I can only reproduce the issue if the current directory (directory used by the HTTP server, see --directory command line option) contains a .ssh/ subdirectory.

      The problem is that the HTTP Header Location starts with "//domain/" and such URL is interpreted as an absolute URL of a new domain name ("domain"), rather than a relative path of the same domain ("localhost").

      Maybe we should simply strip all additional leading slashes to only keep one. Replace "//path" or "/////path" with "/path" for example.

      ---

      By the way, http.server uses urllib.parse.urlsplit() on the request URL without passing its own domain, and urllib.parse.urlsplit() interprets "//attacker.com/path" as if attacker.com is a host with no scheme:

      >>> urllib.parse.urlsplit('//attacker.com/path')
      SplitResult(scheme='', netloc='attacker.com', path='/path', query='', fragment='')

      Maybe parse_qs() should be used instead? Or we should reinject the server domain and port number? I am not sure that it's an issue in practice.

      SimpleHTTPRequestHandler.translate_path('//attacker.com/..%2f..%2f..%2f..%2f..%2f../.ssh') returns os.path.join(self.directory, ".ssh"). I don't think that it's an issue, it sounds like the expected behavior. We don't attempt to reject ".." in URL.

      ---

      To reproduce the issue, I used two terminals.

      Terminal 1:

      $ python3.8 -V
      Python 3.8.7
      $ python3.8 -m http.server
      Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
      127.0.0.1 - - [15/Feb/2021 09:18:20] "GET
      //attacker.com/..%2f..%2f..%2f..%2f..%2f../.ssh HTTP/1.1" 301 -

      Terminal 2:

      $ wget 'http://127.0.0.1:8000//attacker.com/..%2f..%2f..%2f..%2f..%2f../.ssh'
      (...)
      HTTP request sent, awaiting response... 301 Moved Permanently
      Location: //attacker.com/..%2f..%2f..%2f..%2f..%2f../.ssh/ [following]

      --2021-02-15 09:18:20-- http://attacker.com/..%2f..%2f..%2f..%2f..%2f../.ssh/
      Resolving attacker.com (attacker.com)... 45.88.202.115
      Connecting to attacker.com (attacker.com)|45.88.202.115|:80... connected.

      (...)

      wget is redirected and connects to attacker.com.

      The HTTP redirection comes from Lib/http/server.py:

          def send_head(self):
              path = self.translate_path(self.path)
              f = None
              if os.path.isdir(path):
                  parts = urllib.parse.urlsplit(self.path)
                  if not parts.path.endswith('/'):
                      # redirect browser - doing basically what apache does
                      self.send_response(HTTPStatus.MOVED_PERMANENTLY)
                      new_parts = (parts[0], parts[1], parts[2] + '/',
                                   parts[3], parts[4])
                      new_url = urllib.parse.urlunsplit(new_parts)
                      self.send_header("Location", new_url)
                      self.end_headers()
                      return None
                  ...
              ...

      The problem is that the "Location" header starts with "//".

    6. vstinner
      added
      3.9 (EOL)end of lifeend of life
      3.10 (EOL)end of lifeend of life
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      on Feb 17, 2021
    7. 49 remaining items

    8. miss-islington
      added a commit that references this issue on Jun 21, 2022

      gh-87389: Fix an open redirection vulnerability in http.server. (GH-9…

      5715382
    9. gpshead commented on Jun 21, 2022

      @gpshead
      gpshead
      on Jun 21, 2022
      Member
      More actions

      fixed in main, 3.11, and 3.11. the remaining branches are up to the release managers. thanks!

    10. gpshead
      closed this as completedon Jun 21, 2022
    11. ambv
      added 2 commits that reference this issue on Jun 22, 2022

      gh-87389: Fix an open redirection vulnerability in http.server. (GH-9…

      defaa2b

      gh-87389: Fix an open redirection vulnerability in http.server. (GH-9…

      4dc2cae
    12. ned-deily
      added a commit that references this issue on Jun 22, 2022

      gh-87389: Fix an open redirection vulnerability in http.server. (GH-9…

      8a34afd
    13. serhiy-storchaka
      added a commit that references this issue on Jun 26, 2022

      Revert 30935 defer bpo45162 to 312 (#94285)

      1ffde3e
    14. ezio-melotti
      moved this to Done in Release and Deferred blockers 🚫on Jul 2, 2022
    15. mozillazg
      added 2 commits that reference this issue on Sep 27, 2022

      Pull in the http.server vulnerability fix from python/cpython#87389

      a915dbd

      Merge branch 'branch/http_server_vuln_fix' into 'branch/py3.8'

      c6e2fac
    16. ngie-eign commented on Oct 11, 2022

      @ngie-eign
      ngie-eign
      on Oct 11, 2022
      Contributor
      More actions

      For the record, this reproduces on python 2.7 (I used wget --debug to confirm that the Location field was modified). I suspect that this also reproduces on python version <3.7.
      Just a note for others who might be supporting python versions <3.7 in OS distributions.

    17. vstinner commented on Oct 12, 2022

      @vstinner
      vstinner
      on Oct 12, 2022
      Member
      More actions

      CVE-2021-28861 was assigned to this vulnerability.

    18. vstinner
      changed the title [-][security] http.server: Open Redirection if the URL path starts with //[/-] [+][security] CVE-2021-28861: http.server: Open Redirection if the URL path starts with //[/+] on Oct 12, 2022
    19. vstinner commented on Oct 12, 2022

      @vstinner
      vstinner
      on Oct 12, 2022
      Member
      More actions

      I created https://python-security.readthedocs.io/vuln/http-server-redirection.html to track fixes of this vulnerability.

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

    Metadata

    Metadata

    Assignees

    • @gpshead
      gpshead

    Labels

    3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifedeferred-blockerstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-securityA security issueA security issue

    Projects

    • Release and Deferred blockers 🚫
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.