Skip to content

check if absolute path when add target into repo #878

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

Closed
wants to merge 1 commit into from

Conversation

lixuefeng2
Copy link
Contributor

Signed-off-by: lixuefeng (Cloud) [email protected]

repo.py --add doesn't support absolute path. I add check for it in codes.
Actually, relative path with ..(upper folder) has also problem.
The document should add comment to forbid upper folder.

@lixuefeng2
Copy link
Contributor Author

@sebastien Awwad, It seems the CI has problems? The codes should be all right.

Copy link
Member

@lukpueh lukpueh left a comment

Choose a reason for hiding this comment

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

Thanks for pointing out this issue and for providing a patch, @lixuefeng2!

I think the main problem here is that repo.py wants to preserve the full relative path of each target file (target_path) when copying it to the tuf repo directory (repo_targets_path):

https://github.com/theupdateframework/tuf/blob/2c9e3dfacaeb9c2092c81d74aec95905f81db296/tuf/scripts/repo.py#L709-L711

As you pointed out, this breaks if target_path is an absolute path (see os.path.join) or has up-level references (see securesystemslib.util.ensure_parent_dir).

I suggest to either,
(1) first normalize the path, and only consider it (i.e. copy to repo, add to metadata) if it exists and is not absolute, i.e.
foo/../bar --> foo/bar (if exists) --> <REPO_DIR>/targets/foo/bar, or

(2) allow any file (or directory) that exists, but don't preserve the full path when copying, i.e.
/foo/bar --> <REPO_DIR>/targets/bar, and
../baz --> <REPO_DIR>/targets/baz

I think the second approach is less surprising to the user. What do others think? @awwad? @lixuefeng2?

Btw. it might be worth to revise the other file/path related operations in repo.py for consistency, and also update the argparse help messages.



elif os.path.isabs(target_path):
logger.warn('omit this file:' + target_path + ', the target '
Copy link
Member

Choose a reason for hiding this comment

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

logger.warn is deprecated, use logger.warning instead (see linter message)

@lukpueh
Copy link
Member

lukpueh commented Sep 17, 2019

Closing due to inactivity. Re-visit with #811.

@lukpueh lukpueh closed this Sep 17, 2019
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.

2 participants