Skip to content

Metadata API: Reject non-list paths and path_hash_prefixes - #3053

Merged
jku merged 1 commit into
theupdateframework:developfrom
BahaaMattar:fix/delegatedrole-reject-string-paths
Nov 19, 2026
Merged

jku merged 1 commit into
theupdateframework:developfrom
BahaaMattar:fix/delegatedrole-reject-string-paths

Conversation

@BahaaMattar

Copy link
Copy Markdown
Contributor

Description of the changes being introduced by the pull request:

DelegatedRole rejects paths and path_hash_prefixes lists that contain non-strings, but a plain str slips through because iterating a str yields 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 intended files/x.zip is not delegated. A string path_hash_prefixes has 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 ValueError otherwise. The TUF specification defines both as arrays, and the type annotations already say list[str].

Added two cases to invalid_delegated_roles in tests/test_metadata_serialization.py (paths as a string, path_hash_prefixes as a string). Both fail on develop (ValueError not raised) and pass with the change. Locally the full unittest suite passes, coverage report --fail-under 97 passes, and ruff check, ruff format --diff and mypy are clean on the changed files.

Fixes #3052

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>
@BahaaMattar
BahaaMattar requested a review from a team as a code owner November 19, 2026 15:05

@jku jku left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks, this looks good to me

@jku
jku merged commit c9b515b into theupdateframework:develop Nov 19, 2026
17 checks passed
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.

DelegatedRole accepts a string for paths or path_hash_prefixes and then matches the wrong targets

2 participants