fix(router-core): reject empty and whitespace-only metadata tags - #872
Merged
Maki-Zeninn merged 2 commits intoJul 26, 2026
Merged
Conversation
…ration Closes Maki-Zeninn#710 Adds a configurable upper bound on the number of routes that can be registered simultaneously, preventing storage exhaustion and O(n) DoS via recompute_best_route/batch_resolve. Changes: - Add DataKey::MaxRoutes (u32 storage key) - Add RouterError::TooManyRoutes = 17 - initialize() accepts Option<u32> max_routes; None defaults to 1000 - New get_max_routes() read-only getter - New set_max_routes() admin setter (rejects 0 with InvalidRouteName) - Enforce cap in register_route_internal (single choke-point for all registration paths) - Reuse the fetched count for RouteCount increment (eliminates duplicate storage read) - Add TooManyRoutes/InvalidTtlExtension/RecursionLimitExceeded arms to router_error_to_batch - Fix pre-existing duplicate discriminant: RecursionLimitExceeded 15->16, TooManyRoutes = 17 - 11 new tests covering default cap, custom cap at init, setter valid/zero/unauth, register_route at cap, freeing a slot, batch blocked/exactly at cap, lowering cap, raising cap, RouteCount increment
…y and whitespace-only values Closes Maki-Zeninn#713 Previously, metadata validation only checked tag count (max 5) and description length (max 256), but did not validate individual tag values. This allowed empty strings and whitespace-only tags to be stored, which would cause meaningless entries to accumulate and break tag-based filtering. Added per-tag validation in all three validation sites: - register_route inline check - update_route inline check - validate_metadata helper Each tag is now rejected if it is empty (len == 0) or consists entirely of space characters. Uses copy_into_slice byte inspection consistent with the existing validate_route_name pattern for soroban_sdk::String.
|
@joshfatoye0011-bit Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary Closes #713 Metadata validation in contracts/router-core/src/lib.rs checked tag count (max 5) and description length (max 256) but did not validate individual tag values. This allowed empty strings and whitespace-only tags to be stored, causing meaningless entries to accumulate and breaking tag-based filtering/search. ## Changes Added per-tag validation in all three validation sites: - \
egister_route\ inline metadata check - \update_route\ inline metadata check - \�alidate_metadata\ shared helper Each tag is now rejected with \RouterError::InvalidMetadata\ if it is: - Empty (\len == 0) - Whitespace-only (all bytes are \�' ') ## Implementation note \soroban_sdk::String\ does not expose .chars()\ (no-std environment), so validation uses \copy_into_slice\ to inspect raw bytes — consistent with the existing \�alidate_route_name\ pattern in the same file.