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

urllib.request.HTTPPasswordMgr uses commonprefix instead of commonpath #86932

Closed
nagdon mannequin opened this issue Dec 28, 2020 · 2 comments
Closed

urllib.request.HTTPPasswordMgr uses commonprefix instead of commonpath #86932

nagdon mannequin opened this issue Dec 28, 2020 · 2 comments
Labels
3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@nagdon
Copy link
Mannequin

nagdon mannequin commented Dec 28, 2020

BPO 42766
Nosy @orsenthil, @serhiy-storchaka, @Fongeme
PRs
  • bpo-42766 Fix 2 bugs in urllib.request.HTTPPasswordMgr.is_suburi #24181
  • Superseder
  • bpo-46756: Incorrect authorization check in urllib.request
  • 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 = <Date 2022-02-25.12:00:31.021>
    created_at = <Date 2020-12-28.15:42:33.956>
    labels = ['type-bug', 'library', '3.10']
    title = 'urllib.request.HTTPPasswordMgr uses commonprefix instead of commonpath'
    updated_at = <Date 2022-02-25.12:00:31.019>
    user = 'https://bugs.python.org/nagdon'

    bugs.python.org fields:

    activity = <Date 2022-02-25.12:00:31.019>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-02-25.12:00:31.021>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2020-12-28.15:42:33.956>
    creator = 'nagdon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42766
    keywords = ['patch']
    message_count = 2.0
    messages = ['383898', '413986']
    nosy_count = 4.0
    nosy_names = ['orsenthil', 'serhiy.storchaka', 'nagdon', 'Fongeme']
    pr_nums = ['24181']
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '46756'
    type = 'behavior'
    url = 'https://bugs.python.org/issue42766'
    versions = ['Python 3.10']

    @nagdon
    Copy link
    Mannequin Author

    nagdon mannequin commented Dec 28, 2020

    The is_suburi(self, base, test) method of HTTPPasswordMgr in the urllib.request module tries to "Check if test is below base in a URI tree", but it uses the posixpath.commonprefix() function. This is problematic because commonprefix ignores the path structure (for example commonprefix(['/usr/lib', '/usr/local/lib'])=='/usr/l') and therefore the current implementation of is_suburi is essentially equivalent to calling str.startswith after some normalization steps.

    If we want to say that example.com/resource101 is *NOT* below example.com/resource1 in a URI tree, then the call to commonprefix should be replaced by a call to posixpath.commonpath(), which does the right thing.

    @nagdon nagdon mannequin added 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 28, 2020
    @serhiy-storchaka
    Copy link
    Member

    Sorry I did not notice this issue. It is now solved in bpo-46756.

    In any case thank you for the report and the PR.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant