Skip to content

ngclient: Don't use target path as local path #1592

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

Merged
merged 1 commit into from
Sep 30, 2021

Conversation

jku
Copy link
Member

@jku jku commented Sep 27, 2021

Doing so is not always safe and has various other issues
(like target paths "a/../b" and "b" ending up as the same
local path).

Instead URL-encode the target path to make it a plain filename. This
removes any opportunity for path trickery and removes the need to create
the required sub directories (which we were not doing currently, leading
to failed downloads). URL-encoding encodes much more than we really need
but doing so should not hurt: the important thing is that it encodes
all path separators.

Return the actual filepath as return value. I would like to modify the
arguments so caller could decide the filename if they want to. But I
won't do it now because updated_targets() (the caching mechanism)
relies on filenames being chosen by TUF. The plan is to make it
possible for caller to choose the filename though.

This is clearly a "filesystem API break" for anyone depending on the
actual target file names, and does not make sense if we do not plan to
go forward with other updated_targets()/download_target() changes
listed in #1580.

This is part of bigger plan in #1580
Fixes #1571

Signed-off-by: Jussi Kukkonen [email protected]


  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

Doing so is not always safe and has various other issues
(like target paths "a/../b" and "b" ending up as the same
local path).

Instead URL-encode the target path to make it a plain filename. This
removes any opportunity for path trickery and removes the need to create
the required sub directories (which we were not doing currently, leading
to failed downloads). URL-encoding encodes much more than we really need
but doing so should not hurt: the important thing is that it encodes
all path separators.

Return the actual filepath as return value. I would like to modify the
arguments so caller could decide the filename if they want to. But I
won't do it now because updated_targets() (the caching mechanism)
relies on filenames being chosen by TUF. The plan is to make it
possible for caller to choose the filename though.

This is clearly a "filesystem API break" for anyone depending on the
actual target file names, and does not make sense if we do not plan to
go forward with other updated_targets()/download_target() changes
listed in theupdateframework#1580.

This is part of bigger plan in theupdateframework#1580
Fixes theupdateframework#1571

Signed-off-by: Jussi Kukkonen <[email protected]>
@jku jku requested review from MVrachev and sechkova September 27, 2021 08:50
@coveralls
Copy link

Pull Request Test Coverage Report for Build 1277507758

  • 10 of 10 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.02%) to 97.269%

Totals Coverage Status
Change from base Build 1277248985: -0.02%
Covered Lines: 3956
Relevant Lines: 4044

💛 - Coveralls

Copy link
Collaborator

@MVrachev MVrachev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!
I tried to think if there are problem corner cases, but everything seems fine.

Copy link
Contributor

@sechkova sechkova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit annoying that the tests do not include the case it is supposed to fix (targetpath includes subdirectories) because of #1576 but ok.

@jku
Copy link
Member Author

jku commented Sep 27, 2021

A bit annoying that the tests do not include the case it is supposed to fix (targetpath includes subdirectories) because of #1576 but ok.

yes and I should have pointed that out in the PR message, sorry about that... we can either merge this with the pinky promise that the real tests with "directories" are going to be added, or alternatively we combine this PR and 1756 and merge the result to develop.

@MVrachev 1756 is yours, any opinions? I'd maybe lean towards merging this as is, and then you rebasing your work -- is that ok?

@MVrachev
Copy link
Collaborator

A bit annoying that the tests do not include the case it is supposed to fix (targetpath includes subdirectories) because of #1576 but ok.

yes and I should have pointed that out in the PR message, sorry about that... we can either merge this with the pinky promise that the real tests with "directories" are going to be added, or alternatively we combine this PR and 1756 and merge the result to develop.

@MVrachev 1756 is yours, any opinions? I'd maybe lean towards merging this as is, and then you rebasing your work -- is that ok?

I don't have any strong opinions, but if you prefer merging this pr as it is I am okay.
Maybe this will be faster as #1576 is not just about the tests and there could be a discussion.
If you decide to merge it, then as you have mentioned an update on the commit message will be good to happen.

@jku
Copy link
Member Author

jku commented Sep 30, 2021

ok, let's try this: if it doesn't end up working we can always admit defeat and bring back the old API -- we have not promised ngclient is stable yet

@jku jku merged commit bd84dcf into theupdateframework:develop Sep 30, 2021
@jku jku deleted the encode-target-filename branch December 30, 2024 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ngclient: downloading targets fails if targetpath includes subdirectories
4 participants