Repository navigation
Conversation
DelegatedRole checked that every item of paths and path_hash_prefixes is a string, but a plain str is iterable too: a delegation with "paths": "files/*.zip" was accepted and every character was then used as a separate path pattern. The "*" character matches any single-component target path, so unrelated targets were delegated to the role while the intended "files/x.zip" was not. A string path_hash_prefixes behaved similarly, matching far more hash bins than intended. Require both attributes to be lists of strings. Fixes theupdateframework#3052 Signed-off-by: Bahaa Mattar <bahaa.kmattar@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of the changes being introduced by the pull request:
DelegatedRolerejectspathsandpath_hash_prefixeslists that contain non-strings, but a plainstrslips through because iterating astryields one-character strings. A delegation with"paths": "files/*.zip"is then accepted and every character is used as a separate path pattern. Since*matches any single-component target path,is_delegated_path("anything")returns True while the intendedfiles/x.zipis not delegated. A stringpath_hash_prefixeshas a similar effect (with"ab", 231 of 2000 sample target paths matched instead of about 8).This requires both attributes to be lists of strings and raises
ValueErrorotherwise. The TUF specification defines both as arrays, and the type annotations already saylist[str].Added two cases to
invalid_delegated_rolesintests/test_metadata_serialization.py(pathsas a string,path_hash_prefixesas a string). Both fail on develop (ValueError not raised) and pass with the change. Locally the full unittest suite passes,coverage report --fail-under 97passes, andruff check,ruff format --diffandmypyare clean on the changed files.Fixes #3052