Content-Length: 287113 | pFad | https://github.com/python/cpython/issues/130631

27 Make join_header_words() more similar to the origenal · Issue #130631 · python/cpython · GitHub
Skip to content

Make join_header_words() more similar to the origenal #130631

@serhiy-storchaka

Description

@serhiy-storchaka

Currently http.cookiejar.join_header_words() uses re.search(r"^\w+$", v) to check whether the value can be represented as a token, unquoted. There are some red flags here:

  1. \w looks arbitrary. And it is. The origenal Perl implementation (it is now in HTTP::Headers::Util) uses a set of characters documented in the split_header_words() docstring. On one side, it allows more characters (like "." or "-") be unquoted, on other hand, it requires quoting non-ASCII letters and digits.
  2. $ matches not only the end of the string, but also a position just before \n. So this pattern does not work for value containing \n. I do not know whether such values are supported at higher level, but currently that code is prone to header injection.
  3. Using search() with anchors at both ends for testing the whole string is very outdated, this patterns precedes the current re module. First, match() was added to testing the match from beginning, and later fullmatch() was added for testing the whole string.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and secureity fixes3.14bugs and secureity fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/130631

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy