Skip to content

ngclient: avoid lstrip(os.sep) on target paths #1506

Closed

Description

@sechkova

Description of issue or feature request:

During matching of target file path and pathpattern in ngclient/updater.py we normalize the paths by removing the leading os separator.

 # Make sure to strip any leading
 # path separators so that a match is made.
 # Example: "foo.tgz" should match with "/*.tgz".
 if fnmatch.fnmatch(
     target_filepath.lstrip(os.sep), pathpattern.lstrip(os.sep)
 ):

Current behavior:
Normalize file path and pathpattern in case they start with os.sep

Expected behavior:
Define a valid target file path and pathpattern strings and reject everything else.
Don't support corner cases.

Activity

  1. jku commented on Aug 9, 2021

    @jku
    Member

    some additional thoughts here, first for pathpattern:

    • pathpattern comes from the server: the spec "recommends" that '/' is used as the separator. I believe it is impossible for a client implementation to support arbitrary separators -- every implementation needs to choose one and stick with it. I also believe it makes no sense for even the reference implementation to even optionally use/accept anything else than '/'. We should just document that we are stricter than the spec here
    • spec "recommends" that pathpattern not start with a separator: I guess we can leave the pathpattern stripping in there, but for '/' specifically, not for os.sep -- that part is clearly a bug, the client os separator has nothing to do with pathpattern separator which is decided by the server

    For target_filepath:

    • this comes from API user so using os.sep may make sense in some client API -- however I think there is no reason to accept file paths starting with a separator? It's just complexity for no benefit, I would just remove this lstrip().
  2. joshuagl commented on Aug 10, 2021

    @joshuagl
    Member

    RFC2119 states:

    SHOULD This word, or the adjective "RECOMMENDED", mean that there
    may exist valid reasons in particular circumstances to ignore a
    particular item, but the full implications must be understood and
    carefully weighed before choosing a different course.

    IMNSHO the reference implementation does not have a valid reason to ignore any RECOMMENDED/SHOULD entry in the specification and doing so does not make us stricter than the spec.

  3. added
    backlog
    on Aug 18, 2021
  4. MVrachev commented on Aug 18, 2021

    @MVrachev
    Collaborator

    I am going to address this issue in my pr #1512.

  5. self-assigned this
    on Aug 18, 2021
  6. MVrachev commented on Aug 31, 2021

    @MVrachev
    Collaborator

    Fixed by #1512 with commit 34e7546

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

Metadata

Metadata

Assignees

Labels

backlogngclient

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions